PC Review


Reply
Thread Tools Rate Thread

What happen if the UI Thread returned from Application.Run while other thread is trying to call Invoke?

 
 
babylon
Guest
Posts: n/a
 
      24th Mar 2004
the UI Thread can't Invoke the function, right?
and 'the other thread' block indefinitely?

if so, any solution?
thx


 
Reply With Quote
 
 
 
 
TT \(Tom Tempelaere\)
Guest
Posts: n/a
 
      29th Mar 2004
"babylon" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> the UI Thread can't Invoke the function, right?
> and 'the other thread' block indefinitely?
>
> if so, any solution?
> thx
>


Hi,

You would probably get an exception saying that you are trying to call
Invoke on an already disposed object.

You should synchronize, and not call invoke if the application is shutting
down. You can use a mutex for that (System.Threading.Mutex).

HTH,
---
Tom Tempelaere


 
Reply With Quote
 
 
 
 
TT \(Tom Tempelaere\)
Guest
Posts: n/a
 
      29th Mar 2004
"TT (Tom Tempelaere)" <_N_OSPAMtiti____@hotmail.comMAPSO_N_> wrote in
message news:KY%9c.54609$(E-Mail Removed)...
> "babylon" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > the UI Thread can't Invoke the function, right?
> > and 'the other thread' block indefinitely?
> > if so, any solution?
> > thx


> You should synchronize, and not call invoke if the application is shutting
> down. You can use a mutex for that (System.Threading.Mutex).


Perhaps this is not enough information.

Do not let your thread call Invoke on the UI-thread directly.

Instead supply the thread with a delegate, which points to a method that
first checks whether the application is shutting down. For instance, the
delegate could be a method of your form class, which checks a "bool
isFormClosing" in your form class. Initialize it to false. In the form's
closing event handler, begin by setting it to true but you should guard this
by a mutex (just protect setting it to true). Then in your callback
delegate, check isClosing first before calling Invoke and you should guard
the whole method using the same mutex mentioned earlier. This ensures that
Invoke will not get called on a disposed form. Invoke wil be called only if
isClosing is false, and since the whole method is guarded by the mutex, the
call to Invoke is guaranteed to be done on a live form object. If you don't
know how to use Mutex check msdn.

Hope this helps,
Tom.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on Joe Microsoft C# .NET 4 12th Mar 2007 10:59 AM
HELP! When I click set up home or small office network wizard NOTHING HAPPEN !! or NETWORK SETUP WIZARD also nothing happen !! =?Utf-8?B?YXJjaDNk?= Windows XP Setup 1 13th Apr 2004 06:13 PM
HELP! When I click set up home or small office network wizard NOTHING HAPPEN !! or NETWORK SETUP WIZARD also nothing happen !! =?Utf-8?B?YXJjaDNk?= Windows XP Basics 2 28th Feb 2004 12:38 PM
HELP! When I click set up home or small office network wizard NOTHING HAPPEN !! or NETWORK SETUP WIZARD also nothing happen !! =?Utf-8?B?QVJDSCAzRA==?= Windows XP Help 1 28th Feb 2004 02:31 AM
HELP! When I click set up home or small office network wizard NOTHING HAPPEN !! or NETWORK SETUP WIZARD also nothing happen !! =?Utf-8?B?YXJjaDNk?= Windows XP Setup 1 27th Feb 2004 11:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:25 AM.