Dialog boxes and 2-way communication

X

Xlay

I have a form which performs a task similar to a file copy in XP. I am
asked to display a progress in a pop-up box which would allow for the
task to be cancelled by the user. I've added the a form with a label
(for file info), progress bar and a cancel button.
I've made public functions to updated the status bar and the file name
label in the form, but using the [DialogBox].Show() method and calling
those update functions is very slow to respond. (Even using double
buffered dialog and refreshing the box upon update.)

Is there a good tutorial or some alternative suggestions which would
allow me to sample a two-way communication (send updates to the dialog
box for file names/progress and be able to cancel the main form's
process from the dialog?)

Thanks in advance.
 
M

Morten Wennevik

Hi Xlay,

Do your processing (file moving) in another thread. This leaves the graphical user interface to be fully responsive. The processing thread will need to update the progress bar (NB! Invoke/InvokeRequired) and check for a flag set by the user interface thread (lock) or handle the ThreadAbort exception depending on how you want to end the processing if the user cancels the operation.

If you are unfamiliar with multithreading, this can be a daunting task. A good place to start is reading Jon Skeet's article on multithreading

[Multi-threading in .NET]
http://www.yoda.arachsys.com/csharp/threads/

How to update a GUI thread from a processing thread

[Update windows forms from another thread]
http://blogs.msdn.com/ericgu/archive/2003/08/23/52502.aspx

I haven't studied this sample so I can't tell if it will help you out, but it does appear to do something similar to what you need

[Threading out tasks in a C#.NET GUI]
http://www.codeproject.com/csharp/csharp_guithreads.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top