S
snaga.ohme
I have a small problem that's keeping my up late....very late...
It's the standard updating the controls on a windows form from a
separate worker thread problem.
I create a simple form in VB with a Start button (to start the worker
thread) and a single label control
A simple update procedure makes the changes to the label control, i.e.
changes the label text to some value. a delegate to this procedure is
invoked on the UI thread by the worker thread when it's time to
update.
Everything works if all my code is in the form source file, i.e.
Form1.vb., in which case the update procedure is invoked as follows:
me.invoke(updateDelegate)
If I move the code for the worker thread to a separate source file
and contain it within a module (module1.vb), i.e.,
public Module Module1
public sub MyThread()
.....code
' invoke update delegate
Form1.invoke(updateDelegate)
end sub
end module
And then invoke the update delegate but now referencing the UI thread
with Form1.invoke(...) versus me.invoke(...) it will not work.
I get the following error:
Invoke or BeginInvoke cannot be called on a control until the window
handle has been created.
Is there a requirement that everything be in the same source file?
It's the standard updating the controls on a windows form from a
separate worker thread problem.
I create a simple form in VB with a Start button (to start the worker
thread) and a single label control
A simple update procedure makes the changes to the label control, i.e.
changes the label text to some value. a delegate to this procedure is
invoked on the UI thread by the worker thread when it's time to
update.
Everything works if all my code is in the form source file, i.e.
Form1.vb., in which case the update procedure is invoked as follows:
me.invoke(updateDelegate)
If I move the code for the worker thread to a separate source file
and contain it within a module (module1.vb), i.e.,
public Module Module1
public sub MyThread()
.....code
' invoke update delegate
Form1.invoke(updateDelegate)
end sub
end module
And then invoke the update delegate but now referencing the UI thread
with Form1.invoke(...) versus me.invoke(...) it will not work.
I get the following error:
Invoke or BeginInvoke cannot be called on a control until the window
handle has been created.
Is there a requirement that everything be in the same source file?