0

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();
        }
bogdanbrudiu
  • 534
  • 9
  • 32

2 Answers2

0

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

Community
  • 1
  • 1
Jens Granlund
  • 4,950
  • 1
  • 31
  • 31
  • 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 Apr 27 '10 at 07:26
  • 1
    " The user can enter c# code that is compiled "...please NOOOoooo! – Mitch Wheat Apr 27 '10 at 07:28
  • You can perfectly well create a form on a new thread as long as it is a STA one. – Miha Markic Oct 04 '16 at 09:00
0

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
  • 534
  • 9
  • 32