Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

How to close form which created from different thread?

$
0
0
Hi all, I'm having problem closing a form which is compiled in a DLL, and the application is throwing cross thread operation not valid error by saying 'accessed from a thread other than the thread created on'. I've tried to use the InvokeRequired property but it does not solve my problem.
Basically, I have a main program where it reference to two dlls, namely TestWrapper.dll and FormDisplay.dll. The TestWrapper.dll is simply just a wrapper where it access some of the functions in FormDisplay.dll. The FormDisplay.dll contains a main form control and some classes while the TestWrapper.dll is actually accessing some exposed functions in the main form (FormDisplay.dll). My main program is accessing the TestWrapper.dll exposed functions of FormDisplay.dll.
General idea of the calling is Main program calls > TestWrapper.dll calls > FormDislay.dll.

I'm able to load the Form in the FormDisplay.dll which call from my main program but I'm not able to close the form in FormDisplay.dll from my main program by throwing above error that I've stated above.
I knew the problem but I've no idea how can I fix it. I've tried to insert the following code in CloseForm function defined in the TestWrapper.dll, but no luck.


If (m_FormDisplay.InvokeRequired) Then
m_FormDisplay.BeginInvoke(New MethodInvoker(AddressOf CloseForm))
Return
End If
m_FormDisplay.Close()


Please advise.

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>