Question

I have a long running series of operations in a .NET 2.0 BackgroundWorker thread. When I make a call to unmanaged code located in a referenced assembly the UI is frozen until the call completes.

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


Yes, it is a COM component but I'm not sure how to tell if it's STA or not and what the implications/resolution are/is. I make several calls to that component but it is only the long-running ones where I notice the UI becoming unresponsive.

These calls retrieve data from a server.

Was it helpful?

Solution

You've got the COM tag in the question - are you calling into a COM component? Is it an STA component? If so, it may well be marshalling back to do its work on the UI thread somehow. I'll readily admit I'm a long way from being an expert on COM stuff, but I wouldn't be surprised if that were the problem.

What happens if you make the calls from a new thread which you've explicitly created?

OTHER TIPS

Yes and also, does this happen with all unmanaged code or just a specific component or API? If a specific one, what is that unmanaged code doing?

Also, you could simply comment out your current code in the BackgroundWorker (you are running RunWorkerAsync right...) and put a sleep in there. If your GUI becomes unresponsive something's not right, otherwise it's the code you are calling as Jon points out could be the case with COM.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top