[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

can't raise events from ATL control in C# app in VS 2005 debugger

nick

5/22/2007 4:46:00 PM

Hi,
I am seeing problems raising events in a C# app that is using an ATL
control I am developing when I run it in a debug session in VS 2005
that don't appear when I run the same app on its own (outside the
IDE).

I am developing a multithreaded ATL control. This control needs to
raise events from the main thread (in the default STA) and from a
worker thread (running in a second STA). In order to raise events from
the worker thread, I am using the IConnectionPointImplMT solution,
which is described here: http://support.microsoft.com...

I had to make a few fixes to get it to work in ATL 8.0, but it appears
to work correctly now when run in the ActiveX control tester, or if I
run my C# test app on its own.

If I try to run the app in the debugger, I have two problems.

1. I consistently get a failure HRESULT of -2146233040 (0x80131530) or
COR_E_THREADABORTED inside my Fire_OnXXX method in the proxy code in
the ATL control when trying to fire the event.

The specific line that fails is:
hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &params, NULL, NULL, NULL);

2. If I put a breakpoint inside the event handler in my C# code, allow
execution to break and then continue, the errors go away and I am able
to run the app in the debugger.
The first time the event is fired, it will still fail, but after I
break and then continue, subsequent events will make it through OK.
The pConnection->Invoke works fine. Everything is fine until I close
the app - that's when I get this message from the IDE (but only about
half the time):

Managed Debugging Assistant 'DisconnectedContext' has detected a
problem in
'E:\CVS_HOME\DeleteMeApp\bin\Debug\DeleteMeApp.vshost.exe'.
Additional Information: Context 0x1a0528' is disconnected.
Releasing the interfaces from the current context
(context 0x1a0300).This may cause corruption or data loss. To avoid
this problem, please ensure that all
contexts/apartments stay alive until the applicationis completely
done with the RuntimeCallableWrappers that
represent COM components that liveinside them.

As I mentioned earlier, if I run this app on its own, outside the IDE,
there are zero problems that show up and everything runs smoothly.

Any ideas on what could be going wrong?

Thanks,
Nick