OHM,
Consider this sample:
Option Strict On
Option Explicit On
Imports System.Threading
Public Class ThreadMania
Private Shared m_count As Integer
Private Shared Sub Start()
Do Until m_count > 100
m_count += 1
Debug.WriteLine(m_count,
Thread.CurrentThread.GetHashCode().ToString())
Loop
End Sub
Public Shared Sub Main()
Dim t1 As New Thread(AddressOf Start)
Dim t2 As New Thread(AddressOf Start)
t1.Start()
t2.Start()
End Sub
End Class
Both threads are executing at the same time, causing both threads to
update the shared m_count variable, the resultant output is a number
that jumps between thread 1 & thread 2...
Unfortunately I cannot find references that state that static/shared
methods are not thread safe.
Hope this helps
Jay
One Handed Man said:
From help. One sample class.
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.
OHM
OHM,
Also shared
members can be threadsafe.
No there not, where did you read that?
Jay
"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in
message Everything in VB is a class, even a module is a special class. Why
instantiate when you dont need to?. for example, why would you need
to instatiate the function Math.Min , you only need one. Also
shared members can be threadsafe.
OHM
Rexel wrote:
What is the point of having a shared method in a class?
By its definition the shared method is independent of any
instance of the class it is in. So what's the point of it being
there?
It could have just been in class B instead of class A, or in
class C.
Why is it not in a module??
I don't get it.