Hi
I am working on a simple desktop application, it needs to handle some operations like loading a webpage which may block the main thread, so i moved the code to a background worker.
My problem is there is a heavy class named UCSProject, which contains many string and List fields, i need to pass an instance of this class to the background worker, since the class is a bit heavy, i would like to reduce the number of duplicate instances by using the global variable directly, instead of passing it as an argument to the background worker.
To make it short, I just want to know is it safe to access global variables from a background worker thread in C#
It is safe unless until both your threads(background & normal) not modifying the object.
If you want your object to be modified by each other, use Lock