简体   繁体   中英

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?

This should work:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM