All Things Techie With Huge, Unstructured, Intuitive Leaps

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





I had a C# program where I kicked a new thread to check for messages in the database.  I used a delegate in the new thread to call a method in the class that went to the database message table and checked for new messages higher than the message primary key id that it knew about.

It kept throwing this error:

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


As it turns out, I had a couple of variables that were declared but not initialized or set and instead of throwing a null exception, because they were called using a delegate by a different thread, it threw the above error instead.

The fix was to initialize and set the variables.

Hope this helps someone.

No comments:

Post a Comment