开发者

Calling a new Form from a separate thread and avoid frozing the form

I am currently creating a chat system. The receiving end of the client side is managed by a separate thread so that when it receives a 开发者_如何转开发message from another client, a new Form is loaded bearing the message of the sender. The problem is, the newly loaded form is frozen and is not responding [due to the blocked methods I use (?)]. How can I solve that problem? I am new to C# so please put in the code snippet.


It is frozen because you created it on another thread and that thread didn't call Application.Run(). Which is required to 'pump the message loop'. More here.

Don't create windows on another thread. Use BackgroundWorker or Control.BeginInvoke or Dispatcher.BeginInvoke to let the UI thread of your program create the window.


I followed this background worker example with code which worked great for me.

http://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜