Why does calling unmanaged code from the .NET BackgroundWorker thread affect the UI?

I have a long series of operations on a .NET 2.0 thread BackgroundWorker

. When I make a call to unmanaged code located in the specified assembly, the UI is blocked until the call completes.

Why is this? Should I be making these calls from a thread BackgroundWorker

?


Yes it is a COM component, but I am not sure how to determine if it is STA or not and what are the implications / permissions. I make several calls to this component, but these are only long when I notice that the UI is getting unresponsive.

These calls fetch data from the server.

0


source to share


3 answers


You have a COM tag in your question - are you calling a COM component? Is it an STA component? If so, it is entirely possible that this will be done in order to somehow get its work done on the UI thread. I readily admit that I am nowhere near being an expert in COM stuff, but I wouldn't be surprised if that's a problem.



What happens if you make calls from a new thread that you explicitly created?

+3


source


Yes, and does this also happen with all unmanaged code or only with a specific component or API? If any specific, what does the unmanaged code do?



0


source


Alternatively, you can simply comment out your current code in the BackgroundWorker (you are using RunWorkerAsync correctly ...) and go to sleep there. If your GUI becomes immune to something wrong, otherwise the code you are calling, as John points out, might be the case with COM.

0


source







All Articles