views:

55

answers:

2

i have five forms in my c# project. one host an httplistener that i want to run continionsly. when the listener gets a message, it passes it to a static class, which in turn calls the appropriate forms for another processing.

is it possible that the static class calls the new form in a new thread? if so please help me out

+1  A: 

The code in the forms should only deal with the visual aspects of the form. Anything else,especially http listeners, should be handled with separate classes running on background threads.

Sam
please how d i runn http listener in background thread
Smith
@Smith: are you asking about running background threads, or your http listener on one?
Rox
This is what i want to do"should be handled with separate classes running on background threads."
Smith
+1  A: 

"Calling a form" doesn't mean anything, I guess you'd only want to Show() it. Creating a form on a worker thread is never a good idea. Even if you do get the thread state right (STA and message loop), you'll have hard-to-solve Z-order and modality problems.

Simply use Control.Invoke to run code on the UI thread. It should create the form and call its Show() method.

Hans Passant
Additional note: There is also SychronizationContext and friends which are sometimes useful.
pst