Resolved Class Variables in BackgroundWorker

aaaron123@roadrunner.com

Well-known member
Joined
Jan 23, 2011
Messages
47
Programming Experience
10+
I have a class that uses BackgroundWorker.
At the top of the class I have some variables that are accessible to all the class' methods.
I use them all both in methods that run on the main thread and in methods that run in the BackgroundWorker thread.
Everything seems to work OK but I wonder now if its OK for a variable to be accessed by two threads.

Is it.?

If not, is it OK to have them at class level but only used by one thread?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,346
Location
Sydney, Australia
Programming Experience
10+
There's nothing generally wrong with using fields on multiple threads. You may encounter issues if you're reading and writing on different threads at the same time without synchronisation though. As is so often the case, it depends on the specifics.
 
Top Bottom