Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Threading Forms stuff in VB.Net 2005

Status
Not open for further replies.

bsimbeck

Programmer
May 2, 2003
44
US
Here is the exception I am getting:

System.InvalidOperationException: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.

I can provide code
Code:
...
Public Shared WithEvents frmLogin As New frmLogin
Public Shared thrdLogon As Thread
...

public shared sub main()
...
thrdLogon = New Thread(AddressOf LoginThread)
thrdLogon.Start()
frmLogin.BeginInvoke(New frmLogin.disableLoginDelegate(AddressOf frmLogin.DisableLogin))

The last line is the line that the exception appears on. When I step through the code I don't get the exception, so I don't get it. Can anyone help me understand why this is happing.

FYI I just imported this project from VB 2003 to VB 2005 and apparently I was doing naught things the form because of the threading but I still am not sure what is happening here.
 
It's likely that thrdLogon is not fully up and running by the time the BeginInvoke is called. That might be why it throws an exception at runtime, but not when stepping through.

Try checking IsAlive or the ThreadState before calling it.

Also, as you are in VB2005 consider the BackgroundWorker component. It has ready made method and events that make multi-threading easier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top