1 Replies - 465 Views - Last Post: 04 February 2012 - 06:42 AM Rate Topic: -----

#1 thomas130  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 04-March 11

Not sure why this progress feature won't work ?

Posted 03 February 2012 - 08:56 PM

Hi guys

I trying to write a basic progress feature when copying files from a remote location within my console application
Basically there are 13148 within a set of folders. However my application doesn’t seem to update itself when running when the files are being copy over.

I just post the code just in case it's something stupid. I will go into more detail if require

Thanks
Tom

This is just the code for the progress bit since the rest of the program is fine


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.IO;
using System.Threading;


namespace ConsoleApplication3

{
    class Program
    {
        static void Main(string[] args)
        {



                RegistryKey checkreg2 = Registry.CurrentUser.OpenSubKey(@"software\\knowledgeplanning"); 
                decimal check3 = Convert.ToDecimal(checkreg2.GetValue("count"));
                RegistryKey amendreg = Registry.CurrentUser.CreateSubKey(@"software\\knowledgeplanning");
                decimal check4 = Convert.ToDecimal(checkreg2.GetValue("count2"));
                

                decimal cal = (100 / check3) * check4;
                
                while (check4 < check3) 
                {
                    Thread.Sleep(1000);
                    Console.WriteLine(Convert.ToInt32(cal) + "%");
                    
                    
                    //cal = 0;
                    try
                    {
                        amendreg.DeleteValue("count2");
                    }

                    catch { }
                    try 
                    { 
                        decimal grandtotal = 0; 
                        DirectoryInfo file = new System.IO.DirectoryInfo(@"c:\\Knowledge Planning"); 
                        decimal file3 = (file.GetFiles().Length); 
                        grandtotal = 0 + file3; 
                        //Console.WriteLine(file3); 
                        string[] dirs = Directory.GetDirectories(@"c:\\Knowledge Planning"); 
                        foreach (string dir in dirs) 
                        { 
                            DirectoryInfo file2 = new DirectoryInfo(dir); 
                            decimal total = (file2.GetFiles().Length);
                            decimal subtotal = grandtotal = total + grandtotal;
                            decimal finalgrandtotal = grandtotal;
                            amendreg.SetValue("count2", Convert.ToString(grandtotal));
                            
                        } 
                        

                    } 


                    catch 
                    { }




                }

                try
                {
                    amendreg.DeleteValue("count2");
                }

                catch { }


            } 
        } 


        }


Is This A Good Question/Topic? 0
  • +

Replies To: Not sure why this progress feature won't work ?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5628
  • View blog
  • Posts: 12,075
  • Joined: 02-June 10

Re: Not sure why this progress feature won't work ?

Posted 04 February 2012 - 06:42 AM

30 Thread.Sleep(1000);
Evil and you have no real need for this.
Thread sleep stops EVERYTHING on the thread. No copy, no response, no output, no event handling... NADA



Why are you checking the registry for file counts?


I'm going to guess that you aren't seeing updates becuase the thread is completely busy with other stuff. Output is low priority.

Are you familiar with breakpoints so you can walk through this line by line to see what it is really doing?


Learning to debug one's own code is an essential skill. Sadly, one that apparently no college course teaches. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute. Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Form1 talk to Form2



FAQ (Frequently Asked Questions - Updated Jan 2012

Spoiler

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1