Resolved Class Variables in BackgroundWorker

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
216
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?
 
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.
 
Back
Top