views:

308

answers:

5

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?

A: 

This shouldn't happen. Can you post an example?

Nate
A: 

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?

wizlb
+2  A: 

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?

Jon Skeet
A: 

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.

Nate
A: 

OP here... 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.

eft