0

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

Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
  • 1
    "the code broke" is not a good clue to let us understand what happens on your PC. More details are needed. – Steve Apr 30 '12 at 20:55
  • @Steve thanks steve I added it doesnt run the code in the lamda expression sorry i forgot to say that –  Apr 30 '12 at 20:57

1 Answers1

5

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);
}
Steve Danner
  • 21,818
  • 7
  • 41
  • 51