473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Toolbar not Threadsafe?

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!!
Nov 15 '05 #1
2 1327
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

"Sean Dudley" <du*****@uwplatt.edu> wrote in message
news:eW*************@TK2MSFTNGP12.phx.gbl...
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!!

Nov 15 '05 #2
I am an idiot. I never used a delegate to invoke the toolbar's add
function. sorry for the post!!!
"Sean Dudley" <du*****@uwplatt.edu> wrote in message
news:eW*************@TK2MSFTNGP12.phx.gbl...
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!!

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason Morehouse | last post by:
Hello, Just wondering if anyone is using the apache worker module with php? I've complied php5 with zend threadsafe support, and apache2 with the MPM worker module on a Linux box. Everything...
0
by: Stephanie Stowe | last post by:
Hi. I have been posting like a looney on an issue I am working on. I will reiterate the background since you all do not want to remember my issues! I have an ASP app (biggish). We are creating...
102
by: me | last post by:
How do I prevent the save/print/email/mypictures toolbar from popping up when IE users place their cursor over photos at my website? Thank you in advance for your help. Signed, me
9
by: John | last post by:
If a value type is immutable, I guess it's threadsafe to read it? But not threadsafe to assign a new value to it (can any value type be truely immutable? Isn't assigning a totally new value to it,...
2
by: David | last post by:
I have a static method in the dll that looks like this public static int myStaticFunction(int input){ } My question is, should I use a mutex inside the function to ensure that the function is...
6
by: Juan Pedro Gonzalez | last post by:
I wanted to add a Combobox to a toolbar... Kind of the look you get on VisualStudio's toolbar. I've been able to find some VB 6 samples, but the placeholder option is no longer available for...
3
by: Diffident | last post by:
Hello All, Following is a static method. Can you please tell me if this is threadsafe...why? If it is not threadsafe...why? Thank you. public static string...
2
by: Macca | last post by:
Hi, I need a data structure such as an Array/ArrayList/Generic List to hold multiple instances of a user derfined class. This array will be accessed across multiple threads. However I dont...
5
by: Spam Catcher | last post by:
Hi all, I'm accessing a synchronized Streamwriter from potentially several threads to do some logging. Is the Flush command threadsafe too? Should I single thread the Flush command or will the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.