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"
LVL 13
Corey ScheichDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Make sure that the COM object is defined at class level and not in a subroutine or function that will go out of scope.
0
Corey ScheichDeveloperAuthor Commented:
All the ones that need to be accessed later are.
0
Fernando SotoRetiredCommented:
Then I don't know what to tell you, sorry.
0
Corey ScheichDeveloperAuthor Commented:
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
0
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.