Link to home
Start Free TrialLog in
Avatar of Corey Scheich
Corey ScheichFlag for United States of America

asked on

How to keep an object alive

I am receiving the following MDA error

Context 0x1935b8' is disconnected.  Releasing the interfaces from the current context (context 0x1937e0).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.

How do I ensure that ensure that my wrappers and COM objects "Stay Alive"
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Make sure that the COM object is defined at class level and not in a subroutine or function that will go out of scope.
Avatar of Corey Scheich

ASKER

All the ones that need to be accessed later are.
Then I don't know what to tell you, sorry.
The error seems to have had to do more with the form that was running wasn't message pumping.  I created it in it's own STA thread using the following example.  After implementing this I didn't receive this MDA error any more.

Lookup

Walkthrough: Supporting COM Interop by Displaying Windows Forms on a Shared Thread

in the .net framework 2.0 SDK
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial