HI Friends,
I am facing a problem while joining a STA thread to MTA thread. Actually the requirement was some thing like describe below.
1. I have a exe which is using some dialog boxes.
2. These dialog boxes are using MSFlexGrid. This component is a Com component.
3.so in order to run it with Vb.Net exe i had to run this dialog box in a STA thread.
4. to achive this i created a new thread and set the Apartment status STA.
5.it was working fine when i run the code. but if click on exe than at the time of join it throws an unhandled exception.if i click on continue button of exception dialog box it runs successfully. how ever i can not ignore this exception.
6. exception contains below text (i know its a bog message but i am stuck here for last couple of days.).
************** Exception Text **************
System.AccessVi olationExceptio n: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at MSFlexGridLib.I MSFlexGrid.get_ Text()
at AxMSFlexGridLib .AxMSFlexGrid.g et_Text()
at System.Windows. Forms.Control.O nHandleDestroye d(EventArgs e)
at System.Windows. Forms.AxHost.De tachWindow()
at System.Windows. Forms.AxHost.De tachAndForward( Message& m)
at System.Windows. Forms.AxHost.Wn dProc(Message& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
7. COde snippet is like below.
[CODE=vbnet]]
Dim paramtThread As New Threading.Param eterizedThreadS tart(AddressOf DelgInvoke)
Dim exeThread As New Threading.Threa d(paramtThread)
exeThread.SetAp artmentState(Th reading.Apartme ntState.STA)
exeThread.Start (mbrs)// mbrs is a structure variable.
exeThread.Join( )
[/code]
[CODE=vbnet] Private Function DelgInvoke(ByVa l mbrs2 As Members) As Boolean
m_bResFromExeTh read = False
m_bResFromExeTh read = mbrs2.oJobTask. Execute(mbrs2.o PrinterStatus, mbrs2.nError, mbrs2.strError)
Return m_bResFromExeTh read
End Function[/CODE]
Please let me know if any one have any idea. i am totaly clueless here. it would be a great help.
I am facing a problem while joining a STA thread to MTA thread. Actually the requirement was some thing like describe below.
1. I have a exe which is using some dialog boxes.
2. These dialog boxes are using MSFlexGrid. This component is a Com component.
3.so in order to run it with Vb.Net exe i had to run this dialog box in a STA thread.
4. to achive this i created a new thread and set the Apartment status STA.
5.it was working fine when i run the code. but if click on exe than at the time of join it throws an unhandled exception.if i click on continue button of exception dialog box it runs successfully. how ever i can not ignore this exception.
6. exception contains below text (i know its a bog message but i am stuck here for last couple of days.).
************** Exception Text **************
System.AccessVi olationExceptio n: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at MSFlexGridLib.I MSFlexGrid.get_ Text()
at AxMSFlexGridLib .AxMSFlexGrid.g et_Text()
at System.Windows. Forms.Control.O nHandleDestroye d(EventArgs e)
at System.Windows. Forms.AxHost.De tachWindow()
at System.Windows. Forms.AxHost.De tachAndForward( Message& m)
at System.Windows. Forms.AxHost.Wn dProc(Message& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
7. COde snippet is like below.
[CODE=vbnet]]
Dim paramtThread As New Threading.Param eterizedThreadS tart(AddressOf DelgInvoke)
Dim exeThread As New Threading.Threa d(paramtThread)
exeThread.SetAp artmentState(Th reading.Apartme ntState.STA)
exeThread.Start (mbrs)// mbrs is a structure variable.
exeThread.Join( )
[/code]
[CODE=vbnet] Private Function DelgInvoke(ByVa l mbrs2 As Members) As Boolean
m_bResFromExeTh read = False
m_bResFromExeTh read = mbrs2.oJobTask. Execute(mbrs2.o PrinterStatus, mbrs2.nError, mbrs2.strError)
Return m_bResFromExeTh read
End Function[/CODE]
Please let me know if any one have any idea. i am totaly clueless here. it would be a great help.
Comment