none
ActiveX and Context XXX is disconnected problem.

    Question

  • Hello,

    I have been working on a program that when I exit the program via the 'X' close, I get intermittently a Disconnected Context error..

    DisconnectedContext was detected
    Message: Context 0x1a22e8' is disconnected. Releasing the interfaces from the current context (context 0x1a2008).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.

    Mainly , I have some ActiveX that represents some objects that manages a video stream(shows it on the display) - let's name it axDisplay . The axDisplay uses the Connect(...) and Disconnect methods. So, probably, when the application closes I should explicitly Disconnect them...


    I have created an class that inherits from the axDisplay - MyDisplay. maybe is worth implementing the IDisposable method for disconnect the display when disposing...
    Monday, May 25, 2009 9:49 AM

Answers

  • I wrote the function that disconnects and sets to null every "Display" object:

            /// <summary>
            /// Used for resolve closing application anomalies.
            /// To remove if there will be no need of this function.
            /// </summary>
            internal void FinalizeMonitors()
            {
                //VisioWave.ErrorType error;
                //foreach (Monitor monitor in this.MonitorList)
                //{
                //    //error = monitor.Display.Disconnect();
                //    //monitor.Display.Dispose();
                //    //monitor.Display = null;
                //}
            }

    I called this function in the form's

    protected override void OnClosing(CancelEventArgs e)

    method.

    Apparently, this helped.
    So, first time I commented
    monitor.Display = null;
    this line - any runtime error on form closing.

    then
    monitor.Display.Dispose();
    this line - any error

    finally, I commented all the FinalizeMonitors code(but method declaration).

    I had no errors on Form closing anymore...

    I don't know very much what happens, but if I have no errors this is OK for me...

    Best regards, Sergiu
    • Marked as answer by Sergiu Dudnic Wednesday, May 27, 2009 9:49 AM
    Wednesday, May 27, 2009 9:48 AM

All replies

  • Hi,

    Have you tried Disconnect method in the FormClosing event handler?

    Harry
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, May 27, 2009 4:46 AM
  • I wrote the function that disconnects and sets to null every "Display" object:

            /// <summary>
            /// Used for resolve closing application anomalies.
            /// To remove if there will be no need of this function.
            /// </summary>
            internal void FinalizeMonitors()
            {
                //VisioWave.ErrorType error;
                //foreach (Monitor monitor in this.MonitorList)
                //{
                //    //error = monitor.Display.Disconnect();
                //    //monitor.Display.Dispose();
                //    //monitor.Display = null;
                //}
            }

    I called this function in the form's

    protected override void OnClosing(CancelEventArgs e)

    method.

    Apparently, this helped.
    So, first time I commented
    monitor.Display = null;
    this line - any runtime error on form closing.

    then
    monitor.Display.Dispose();
    this line - any error

    finally, I commented all the FinalizeMonitors code(but method declaration).

    I had no errors on Form closing anymore...

    I don't know very much what happens, but if I have no errors this is OK for me...

    Best regards, Sergiu
    • Marked as answer by Sergiu Dudnic Wednesday, May 27, 2009 9:49 AM
    Wednesday, May 27, 2009 9:48 AM
  • Hi,

    So putting disconnect method in the FormClosing event handler helps?

    Harry
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, May 28, 2009 1:35 AM
  • First Time - yes, but after that I commented the disconnect code... And received any errors... this is very strange.
    Best regards, Sergiu
    Thursday, May 28, 2009 10:15 AM