user1158903
user1158903

Reputation:

inline backgroundworker

In C# I have two blocks of code which open and write to processes which I open and I'd like them to run at the same time in the same function. I found BackgroundWorker with anonymous methods? but when i tried to impliment the it doesn't run the code in the lambda expression.

BackgroundWorker bgwanalysis = new BackgroundWorker();
bgwanalysis.DoWork += delegate
{
 ...codehere..
};

while (bgwanalysis.IsBusy)
{
  Thread.Sleep(2000);
}

I know I'm missing something basic could someone fill me in? Thanks

Upvotes: 0

Views: 3770

Answers (1)

Steve Danner
Steve Danner

Reputation: 22168

From what you're showing, I'm not seeing the line:

bgwanalysis.RunWorkerAsync();

So your code becomes:

BackgroundWorker bgwanalysis = new BackgroundWorker();
bgwanalysis.DoWork += delegate
{
 ...codehere..
};

bgwanalysis.RunWorkerAsync();

while (bgwanalysis.IsBusy)
{
  Thread.Sleep(2000);
}

Upvotes: 5

Related Questions