473,387 Members | 1,812 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,387 software developers and data experts.

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 2379
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
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
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
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
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
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
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
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
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
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
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
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.