Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
misc
exam.security
microsoft_update_catalog
msdn.annotations
msdn.drgui.discussion
msdn.duwamish
msdn.general
msdn.magazine
msdn.soaptoolkit
msdn.webservices
msdntraining
opsmgr.connectors
opsmgr.sp1
technet
technet.howtofeedback
technet.howtoneeds
technet.magazine
technet.technettalks
  
 
date: Wed, 13 Apr 2005 20:41:01 -0700,    group: microsoft.public.msdn.drgui.drguidotnet.discussion        back       


UI and Threads   
I am currently working on a project that needs to use a thread to perform a 
background process. The question I have is if an event is raised from a 
business object that creates a new thread, does it need any special handling 
to process on the UI thread correctly?

For example, I have an application that performs a background task and then 
displays a small popup window that disappears after a second or two. The 
logic flows this way:

1) New business object created
2) Business object creates a new thread and then raises a completed event
3) The UI captures the completed event and displays the popup.

I'm currently doing this and getting a little black box. Using the 
debug.writeline I'm writing all events handled. The only one being handled is 
the form.load event. All other events are ignored. However, if I create the 
popup from a button on the main form I have no trouble. It works correctly. 
Any help would be appreciated.

Thanks!
-- 
Chris Quick
date: Wed, 13 Apr 2005 20:41:01 -0700   author:   Chris Q.

RE: UI and Threads   
To call a method in a Control on the main thread (message loop thread) from 
another thread you must call Invoke which will marshall the data onto the 
main thread if required and carry out execution on the main thread correctly. 
Doing it from another thread will result in a PostMessage rather than a 
SendMessage  - google this for many deep explanations. But for a quick fix 
create a 'ShowPopup' method on your form and call something like 
myForm.Invoke( new MyHandler( myForm.ShowPoup ), null )

James 

"Chris Q." wrote:

> I am currently working on a project that needs to use a thread to perform a 
> background process. The question I have is if an event is raised from a 
> business object that creates a new thread, does it need any special handling 
> to process on the UI thread correctly?
> 
> For example, I have an application that performs a background task and then 
> displays a small popup window that disappears after a second or two. The 
> logic flows this way:
> 
> 1) New business object created
> 2) Business object creates a new thread and then raises a completed event
> 3) The UI captures the completed event and displays the popup.
> 
> I'm currently doing this and getting a little black box. Using the 
> debug.writeline I'm writing all events handled. The only one being handled is 
> the form.load event. All other events are ignored. However, if I create the 
> popup from a button on the main form I have no trouble. It works correctly. 
> Any help would be appreciated.
> 
> Thanks!
> -- 
> Chris Quick
date: Thu, 9 Jun 2005 09:49:06 -0700   author:   James

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us