[C#] Updating the form half way through a function?

Soldato
Joined
12 Apr 2004
Posts
11,788
Location
Somewhere
[C#] Updating the form in real time?

I've written a little backup utility in C# which copies the contents of one directory to another with several options, and I want to be able to add an item to a listbox for each file that is copied, in real time.

So far, I have a class that does the file copying, and raises an event every time a file is copied, which is handled back in the form file, and an item is added to the listbox. However, the changes can't be seen until the backup object has finished doing its thing and control has passed back into and through the buttonBackup_Click() event handler.

Is there a way of getting the changes to be visible as the files are being copied? :confused:

Any help appreciated :)
 
Last edited:
Mickey said:
To do what you're doing properly though you'd normally make the application threaded, doing the actual work in another thread and make the changes to the main form using a delegate.
I did think of that, but I thought it would probably be overkill for such a simple application, and I'm probably not experiened enough with C# to do that yet. I'll look into it though :)
 
I found a way of doing it without Selecting the bottom item actually:
Code:
int maxVisibleItems = listBoxProgress.Height / listBoxProgress.ItemHeight;
listBoxProgress.TopIndex = listBoxProgress.Items.Count - maxVisibleItems;
Works perfectly!

Thanks for the help :)
 
Edit: Nevermind, got it all working now! Much faster than it was before, and the UI is fully responsive during backup :cool:
Hurrah for multithreading, thanks for the help all :D
 
Last edited:
Back
Top Bottom