473,804 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1353
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*****@uwplat t.edu> wrote in message
news:eW******** *****@TK2MSFTNG P12.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*****@uwplat t.edu> wrote in message
news:eW******** *****@TK2MSFTNG P12.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
2770
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 seems sweet. mysqli_thread_safe() reports true... anyone know if this configuration may include modules that aren't threadsafe? with-apxs2=/usr/local/apache2/bin/apxs with-gd enable-gd-native-ttf
0
1345
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 the first of many JSP apps. Until such time as we re-engineer our ASP apps for our new JSP / Java / Websphere environment, we need a session bridge. The services are always initiated from within ASP where they are authenticated and authorized....
102
7405
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
3195
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, like doing an modification, when no references are involved? I don't know enough about CLR) At the moment the whole: lock(anobject) {
2
2921
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 threadsafe? This is used for ASP.NET. I am asking this question without knowing how IIS works as a multi-threaded application. Does each websession get a thread? If so, if two users are calling the static function at the same time, do they
6
3133
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 ToolbarButtons... Does anyone know how this could be done? Looking forward to hear from you,
3
2179
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 GetCachedApplicationWideObject(string HashtableKey) { //Cache holds the hashtable
2
3458
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 want to lock the array itself as this will cause poor performance due to the array being accessed frequently. If I make the User defined class threadsafe will this be enough to make
5
5733
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 Synchronized streamwriter handle that for me? Thanks!
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10311
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.