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
Oliver Sturm - 20 Aug 2005 13:32 GMT
> 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

Signature
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Metallikanz! - 20 Aug 2005 18:16 GMT
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!
> Hello
>
[quoted text clipped - 9 lines]
> Regards
> Bassam
Mark R. Dawson - 21 Aug 2005 04:27 GMT
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 :-)
> 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.
>
[quoted text clipped - 13 lines]
> > Regards
> > Bassam
alantolan@users.com - 22 Aug 2005 20:19 GMT
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.