Running Visio On two different UI threads not at the same time.
             

Hello,

Sorry if i have posted this in the wrong section i couldn't see a area for embedded Visio controls.

As the title states what i am trying to do is run two different UI threads where the user will be able to load the control on one and dispose of it before launching the secondary UI thread/Form and then loading the control on here.

i have had this problem for another control in the past and it turned out i wasn't clearing up the control enough. once i had everything was fine and it worked a charm.

Public Class Form1

    Private _visio As AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl

    Private Sub ButtonCreate_Click(sender As System.Object, e As System.EventArgs) Handles ButtonCreate.Click
        Try
            _visio = New AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl

            Panel1.Controls.Add(_visio)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub ButtonDelete_Click(sender As System.Object, e As System.EventArgs) Handles ButtonDelete.Click
        Try
            Panel1.Controls.Remove(_visio)
            _visio.Window.Application.Quit()
            _visio.Dispose()
            _visio = Nothing
    

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ButtonForm2_Click(sender As System.Object, e As System.EventArgs) Handles ButtonForm2.Click
        ShowContainerForm()
    End Sub


    Private Sub StartContainerThread(ByVal parameters As Object)
        Dim containerFormType As Type = GetType(Form2)
        Dim constructorInfo As Reflection.ConstructorInfo = containerFormType.GetConstructor(New Type() {})

        Dim container As Form2

        container = CType(constructorInfo.Invoke(New Object() {}), Form2)

        If Not container.IsDisposed Then
            System.Windows.Forms.Application.Run(container)
        End If
    End Sub

    Public Sub ShowContainerForm()
        Dim containerThread As New Threading.Thread(New Threading.ParameterizedThreadStart(AddressOf StartContainerThread))
        containerThread.SetApartmentState(Threading.ApartmentState.STA)
        containerThread.Start()
    End Sub


End Class
Public Class Form2
    Private _visio As AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl
    Private Sub ButtonCreate_Click(sender As System.Object, e As System.EventArgs) Handles ButtonCreate.Click
        Try
            _visio = New AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl
            Panel1.Controls.Add(_visio)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub ButtonDelete_Click(sender As System.Object, e As System.EventArgs) Handles ButtonDelete.Click
        Try
            Panel1.Controls.Remove(_visio)
            _visio.Window.Application.Quit()
            _visio.Dispose()
            _visio = Nothing
        
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class


I have also asked this question here originally before finding this section, so i apologies for the double post and will gladly remove one if you let me know where it should belong.

https://social.msdn.microsoft.com/Forums/office/en-US/977ceccb-d743-4570-9aa4-f9253aec6685/running-visio-on-two-different-ui-threads-not-at-the-same-time?forum=vbgeneral



March 13th, 2015 1:41pm

Hello George,

Thank you for the reply,

I have been attempting to look through the forums however i will admit i did get confused as to where to post things.

I believe the answer i got given in the other thread is correct and am now looking for a way to close this question.

Free Windows Admin Tool Kit Click here and download it now
March 17th, 2015 8:43am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics