I used the Backgroudworker to do some work to do some labor-intensive tasks.
public void ConnectDataProvider()
{
bgw = new BackgroundWorker();
bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
}
Another method starts a background worker:
public void StartPolling()
{
bgw.RunWorkerAsync();
}
Then I processed the event:
void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
StartPolling();
}
void bgw_DoWork(object sender, DoWorkEventArgs e)
{
WriteData();
}
As you can see, I started working on the completion. Now it works for one desktop.
Now I want a collection, and each item must complete this task. However, with the above concept, it will continue to work in the first working run, as it will launch the working one. I think maybe a combined timer could solve the situation to give other workflows a way.
Is BackgroundWorker a good choice? Is it common to reuse BackgroundWorker like me?
1: clair: , , , BackgroundWorker. , . .
2: , , , , , .
3: ( , ), : , gps. , . . Ihad BackgroundWorker . , , . .
. ( DoWrite). BackgroundWorker , , . , .