Search code examples
c#winformsbackgroundworker

Secondary form freezes from c# backgroundworker


I have a simple windows form in c# that has a background worker attached to it (simple drag-n-drop from the designer). A few seconds after launching the application a background worker is programmed to start. In the DoWork() method I declare a Form2 object (a simple form that I created with the designer which only has a label on it) and I call form2.Show(). The problem is that form2 freezes as soon as it's shown and I can't understand why. Can anyone explain this?


Solution

  • This should work:

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Invoke((MethodInvoker) delegate(){
                new Form2().Show();
            });
        }