BackgroundWorker inside a user defined function

T

Torben Laursen

I have a Excel COM written in C# that has a number of user defined
functions. (UDF)
Some of them take a long time (5-10 minuts) to complete so I would like to
run them code inside a thread so it does not lock Excel and the user can
stop them it if he wants.
I have a backgroundworker inside a class (calcthread) and call it like this
inside the UDF
calcthread.Execute(Mixture, ModuleInfo); ///starts the thread

while(calcthread.IsBusy) ///waite for the thread to finish by checking
IsBusy in the backgroundworker, so the UDF can return the result

{


}

///Code to return the result.

The problem that I have is that the while code makes the code hang.

The thread finish inside the event DoWork but the event RunWorkerCompleted
is never called.

If I remove the while code RunWorkerComplete is called but then I dont know
how to make the UDF return the results when the thread is done.

The problem seems my call to IsBusy.

Can anyone tell me how to solve this problem?



Thanks Torben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top