Threading safety with windows form
-
Hi all, I read some books that manipulating the window form components using a thread other than a main thread can cause bugs that are not repeatable. Is there any example code of how to get around this ? And next, the documentation in MSDN often have the following statement. Its confusing for me. So when is a member public static and when is it an instance member? :confused: Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe
-
Hi all, I read some books that manipulating the window form components using a thread other than a main thread can cause bugs that are not repeatable. Is there any example code of how to get around this ? And next, the documentation in MSDN often have the following statement. Its confusing for me. So when is a member public static and when is it an instance member? :confused: Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe
You can use the Invoke method of the Control class to safely call a piece of code that does a UI task. There's a lot of other things to learn about thread safety. Have fun
-
Hi all, I read some books that manipulating the window form components using a thread other than a main thread can cause bugs that are not repeatable. Is there any example code of how to get around this ? And next, the documentation in MSDN often have the following statement. Its confusing for me. So when is a member public static and when is it an instance member? :confused: Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe
A member is public static when it is declared public static and therefor can be accessed without an instance of the class. An instance member on the other side can only be accessed by using an object of the class. A short example:
public class Test
{
// No instance needed to access this member
public static int StaticMember;
// Need an instance to access this member
public int InstanceMember;
}Test.StaticMember = 5;
Test obj = new Test;
obj.InstanceMember = 5;