Help, please!
I have seen a couple of threads about this message, but they seem to
have a much more complicated situation than mine, and they aren't much
help.
I have a form from which a call is made to a serial port, using
"Friend WithEvents sPort As SerialPort". This goes to a piece of kit
which, after a couple of seconds, returns a message. Now, because it's
listening for it in a global module, and also the use of SerialPort
takes place on a new thread, I use an EventHandler to raise an event
which the original form can handle, to show the returned data, and an
"Invoke" to handle cross-thread calls. I also have
"Control.CheckForIllegalCrossThreadCalls = False" in the form. But
when it hits a "Me.invoke" (or <any control on the form>.invoke), it
fails with this message:
"Invoke or BeginInvoke cannot be called on a control until the window
handle has been created."
Now I'm not doing anything fancy to create the form, it's just in the
designer. And the form is not closed or made invisible between
actioning the "send" and receiving the event from the "RaiseEvent" in
the routine that's listening for the returned data. Looking at the
other threads, I tried to create a handle (dim xx as Long = Me.Handle)
- but it said "Cannot access a disposed object." So, WHY is my form
disposed??? Given that it is, I can see why I get the first error, but
what on earth is disposing it????
Help, please!!
Peter Royle
Dick Grier - 13 May 2008 17:07 GMT
I have never seen this.... However, I enable the serial port in the form
Load event (there certainly is no need to do this earlier). Perhaps you can
do the same?
Dick

Signature
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.