views:

48

answers:

2

I have a thread that needs to create a popup Window. I start the thread using ThreadPool.QueueUserWorkItem(new WaitCallback(CreatePopupinThread)) Thew thread creats a new form. The application freases in the new Form constructor at CreateHandle. The Worker Thread is locked... How can I fix this?

this is how I create the form

var form = new ConfirmationForm
                           {
                               Text = entry.Caption,
                               Label = entry.Text,
                           };

In the constructor the thread enters a deadlock

public ConfirmationForm()
        {
            InitializeComponent();
        }
A: 

I think it would be better to create the "popup window" on the UI thread and then create a thread in the "popup window" to process what you want it to do.

As I suspected, you can´t show a form created on a non ui thread.
See this answer: Possible to construct form on background thread, then display on UI thread

Jens Granlund
it is not that simple... the thread is actualy a "user code". The user can enter c# code that is compiled at runtime and it is runed at certain events.. This "user code" has some misc methods and one of them popups a message...
bogdanbrudiu
" The user can enter c# code that is compiled "...please NOOOoooo!
Mitch Wheat
A: 

I have fixed the problem... The deadlock whas triggered because the tread start whas done in a Form Activated Event... I have moved it to a Shown event and now it works ok...

bogdanbrudiu