Threading question - ensure execution of a block of code

  • Thread starter Thread starter kpg
  • Start date Start date
K

kpg

Is there a way to protect a section of code so that all the statements in
the protected block are executed without being interrupted by another
thread?

I have a worker thread that adds a value to an array (a circular buffer)
then increments the array index. If the user clicks on a button of a form
in the main thread, sometimes the main thread code will then access the
array after the value has been added, but before the array index has been
updated.

I know I've seen ways to protect code in other languages (Pascal or Ada I
think) but how can this be done in vb.net?

thanks,
kpg
 
Back
Top