user interface feedback

  • Thread starter Thread starter Bassam
  • Start date Start date
B

Bassam

Hello

does anyone know the method of refreshing the user interface while a windows
form is handling deep calculations , i want to reflect some data on some
labels and text boxes but the from is freeze till calculation is finished ,
i know i can use another thread but i remember there was a very simple
method to do the events of the form and show the results immediately,
something like .DoEvents

any help appreciated

Regards
Bassam
 
Bassam said:
does anyone know the method of refreshing the user interface while a windows
form is handling deep calculations , i want to reflect some data on some
labels and text boxes but the from is freeze till calculation is finished ,
i know i can use another thread but i remember there was a very simple
method to do the events of the form and show the results immediately,
something like .DoEvents

What you mean is probably Application.DoEvents(). But I seriously advise
you to do this stuff in another thread - it's the much cleaner and more
flexible way, and it will leave your UI a lot more responsive than any
approach using DoEvents().



Oliver Sturm
 
If you do not want to directly manipulate threads to get your work done, wrap the long running method with a delegate and do an asynchronous invocation, the FW will take care of queuing and executing it on the thread pool thread.

HTH, Metallikanz!
 
You can use the threadPool in this case because it does not look like you are
using many threads, but in general long running tasks should not be run using
threads from the threadpool. Threadpool threads are a shared resource, 25
threads per thread per processor, so tying up these threads can lead to
actions being delayed if there are not threads currently available in the
pool. For any long running task it is recommended that you create your own
thread to handle the task.

Also when running actions from a threadpool thread any exception that
happens in your code will be supressed by the CLR if you do not handle it
correctly, so you need to take special care in your exception handling :-)
 
Also, if you are going to be using a separate thread (either explicitly
creating one or invoking a delegate) you should not use that thread to
update the UI. Only the UI thread should do this.

Check out Ted Pattison's articles on MSDN Magazine for some nice intro
articles on threading and updating the UI.

hth,
Alan.
 
Back
Top