all groups > c# > january 2004 >
You're in the

c#

group:

Toolbar not Threadsafe?


Re: Toolbar not Threadsafe? Justin Rogers
1/19/2004 10:49:15 PM
c#:
You have to check the InvokeRequired property of your Toolbar control to make
sure you don't
need to call Invoke to get the call on the primary UI thread. In your case you
think the the main
thread is handling the event you toss, but it probably isn't. you are probably
still on the watcher thread.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

[quoted text, click to view]

Toolbar not Threadsafe? Sean Dudley
1/19/2004 11:45:28 PM
I have a toolbar control in my main form. I thread out a an instance of a
watcher class (just looking for new processes and raising an event when one
arises) as a background thread. my main form receives events from the
watcher thread.

Now, within the event handler on the main thread (which is firing just fine)
I attamept to add a new toolbar button to my toolbar based on the event
args. If I generate labels or standard form buttons everything is fine.
But if I try to add a button to a toolbar the program will seize up
(actually the toolbar control seems to lock up since it is the first item to
stop drawing itself). Sometimes I'll get a NullReference exception out of
the fiasco, other times I'll get a "Window handle already in use" error.
Neither of which make any sense given that everything is initialized and not
null, and all I am trying to do is add a button. If I do this identical
routine without threading out the watcher everything works fine.

The only difference between working versions and non-working is the
background thread approach.

Is this a bug?

Thanks!!

Re: Toolbar not Threadsafe? Sean Dudley
1/20/2004 1:04:48 AM
I am an idiot. I never used a delegate to invoke the toolbar's add
function. sorry for the post!!!


[quoted text, click to view]

AddThis Social Bookmark Button