Correct Approach to Multi-Threading Issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've done a lot of reading about multi-threading (I come from a VB6
background so these things are new to me) but I can't find an example of my
exact scenario.

It's very simple, I've got a worker thread which needs to read the Checked
property of a checkbox on a form. I gather that I can't read this property
from the worker thread (only the UI thread) so is the best approach to use a
(VB.NET) function to read the checkbox property and use Me.Invoke to invoke
the function in the UI thread?

Thanks in advance,

Colin
 
All you need is a variable with sufficient scope to be be visible to both
the UI thread and the worker thread.

In the CheckChanged event handler for the Checkbox, set the variable to the
value of the Checkbox's Checked property.

The next time the worker thread reads the variable, it will 'notice' any
change.
 
Thanks for the reply.

If I use this approach won't I need to use SyncLock to make sure the
variable isn't being accessed by the UI and worker threads at the same time?
 
Quite possibly. Have a read up on it.


Colmeister said:
Thanks for the reply.

If I use this approach won't I need to use SyncLock to make sure the
variable isn't being accessed by the UI and worker threads at the same
time?
 
Back
Top