C#: RunWorkerAsync() doesn't trigger DoWork()

前端 未结 4 1323
春和景丽
春和景丽 2021-01-21 03:28

I am writing a small forms based application to connect to an LDAP server, and I wanted the \"connect\" button to work in the background. So I was following the information and

相关标签:
4条回答
  • 2021-01-21 04:13

    RunWorkerAsync() starts the worker thread and immediately returns thus the debugger seems to "step through it". Set a breakpoint in the worker_DoWork() method.

    0 讨论(0)
  • 2021-01-21 04:14

    You have not set

    worker.DoWork += new DoWorkEventHandler(worker_DoWork);

    before calling worker.RunAsync()

    0 讨论(0)
  • 2021-01-21 04:18

    You are never wiring up the event.

       public Form1()
        {
            InitializeComponent();
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);
        }
    
    0 讨论(0)
  • 2021-01-21 04:31

    If u still have event and is not working, try the following

    Just call

    System.Windows.Forms.Application.DoEvents();

    before calling RunWorkerAsync()

    0 讨论(0)
提交回复
热议问题