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
- Edited by MaceySoftware Friday, March 13, 2015 1:44 PM