471,627 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Bad Threading..

Got the below class, it has one thread that does a continuous loop getting
network packets, it all seems to work well, except when i try to open a
results Form "myTestForm" from within the thread, it just hangs.. tried
threading TestForm, but not quite sure how to do that and whether or not it
would solve my problem..


public class ListenerForm : System.Windows.Forms.Form{

private void Form_Load(object sender, System.EventArgs e){
System.Threading.Thread t = new System.Threading.Thread(new
System.Threading.ThreadStart(ListenLoop));
t.Start();
}

private void ListenLoop(){
while(listening){
TestForm myTestForm = new TestForm();
myTestForm.Visible = true;
}
}
}
Nov 29 '05 #1
2 1201
Found a workaround, using Invoke.. though seems like a strange solution to
the problem..

private void ListenLoop(){
while(listening){
this.Invoke(new EventHandler(new EventHandler(test)));
}
}

public void test(object sender, EventArgs e){
TestForm myTestForm = new TestForm();
myTestForm.Visible = true;
}

<Stoic> wrote in message news:uw*************@TK2MSFTNGP09.phx.gbl...
Got the below class, it has one thread that does a continuous loop getting
network packets, it all seems to work well, except when i try to open a
results Form "myTestForm" from within the thread, it just hangs.. tried
threading TestForm, but not quite sure how to do that and whether or not
it would solve my problem..


public class ListenerForm : System.Windows.Forms.Form{

private void Form_Load(object sender, System.EventArgs e){
System.Threading.Thread t = new System.Threading.Thread(new
System.Threading.ThreadStart(ListenLoop));
t.Start();
}

private void ListenLoop(){
while(listening){
TestForm myTestForm = new TestForm();
myTestForm.Visible = true;
}
}
}

Nov 29 '05 #2
>though seems like a strange solution to
the problem..

It is not strange. It is the standard way to invoke a control's method
from other thread. Make sure you always do this.

Nov 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

65 posts views Thread by Anthony_Barker | last post: by
2 posts views Thread by Egor Bolonev | last post: by
6 posts views Thread by CK | last post: by
2 posts views Thread by Vjay77 | last post: by
11 posts views Thread by Paul Sijben | last post: by
reply views Thread by kingcrowbar.list | last post: by
7 posts views Thread by Mike P | last post: by
126 posts views Thread by Dann Corbit | last post: by
reply views Thread by leo001 | last post: by

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.