473,508 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading problem

I have a form which acts as an mdi parent. It receives an event which has a name and message
It creates a new form for every name and displays messages within that form
The event handler calls RouteMessage which dtermines if the form already exists (using a hashtable) and tries to create the form if necessary
Unfortunately, this fails with the exceptio

'Controls created on one thread cannot be parented to a control on a different thread.

So the original parent form has been created on one thread and all the events are being handled on another thread
Any suggestions as to how I might solve this

Stev
private void MonitorServer_OnMonitorEvent(object file, MonitorEventArgs args

RouteMessage(args.serviceName,args.message)

public void RouteMessage(string serviceName,string message

if (serviceForms.Contains(serviceName)

((DisplayForm)serviceForms[serviceName]).AddMessage(message)

els

CreateNewForm(serviceName,message)
public DisplayForm CreateNewForm(string name,string message

DisplayForm displayForm = new DisplayForm(name)
displayForm.MdiParent = this
displayForm.Show()
if (message != null
displayForm.AddMessage(message)
serviceForms.Add(name,displayForm)
return displayForm

Jul 21 '05 #1
2 2386
Steve <an*******@discussions.microsoft.com> wrote:
I have a form which acts as an mdi parent. It receives an event which
has a name and message. It creates a new form for every name and
displays messages within that form. The event handler calls
RouteMessage which dtermines if the form already exists (using a
hashtable) and tries to create the form if necessary. Unfortunately,
this fails with the exception

'Controls created on one thread cannot be parented to a control on a
different thread.'

So the original parent form has been created on one thread and all
the events are being handled on another thread. Any suggestions as to
how I might solve this?


As with everything UI-based, only do anything with the UI on the UI
thread which created the main window. Use Control.Invoke to invoke a
delegate on that UI thread.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Steve <an*******@discussions.microsoft.com> wrote:
I have a form which acts as an mdi parent. It receives an event which
has a name and message. It creates a new form for every name and
displays messages within that form. The event handler calls
RouteMessage which dtermines if the form already exists (using a
hashtable) and tries to create the form if necessary. Unfortunately,
this fails with the exception

'Controls created on one thread cannot be parented to a control on a
different thread.'

So the original parent form has been created on one thread and all
the events are being handled on another thread. Any suggestions as to
how I might solve this?


As with everything UI-based, only do anything with the UI on the UI
thread which created the main window. Use Control.Invoke to invoke a
delegate on that UI thread.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3

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

Similar topics

65
6663
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
19
6442
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
17
2407
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next...
2
2954
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
77
5208
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
11
4989
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found...
17
6389
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
9
1836
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
5
6921
by: CCLeasing | last post by:
For an application I'm creating I want to create a 'fake' progress bar. By fake I mean a progress bar that looks like it's doing something but actually isn't. I know philosophically this isn't...
126
6609
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7326
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,...
1
7046
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...
0
7498
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...
0
5629
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,...
1
5053
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...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
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 ...
1
766
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.