PDA

View Full Version : سوال در رابطه با AutoResetEvent



sg.programmer
یک شنبه 13 دی 1388, 22:26 عصر
AutoResetEvent read = new AutoResetEvent(false);

AutoResetEvent

چیه
چه کاربردی داره
کجا بکار می ره
یه مثالی میشه بزنید
تشکر

AliRezaPro
یک شنبه 13 دی 1388, 22:39 عصر
توضیح با مثال

http://msdn.microsoft.com/en-us/library/system.threading.autoresetevent.aspx

sg.programmer
دوشنبه 14 دی 1388, 09:18 صبح
لطفا فارسی باشه

sg.programmer
چهارشنبه 16 دی 1388, 10:37 صبح
AutoResetEvent read = new AutoResetEvent(false);

AutoResetEvent

چیه
چه کاربردی داره
کجا بکار می ره
یه مثالی میشه بزنید
تشکر

لطفا یکی یه چیزی بگه :متفکر:

amirzandi
پنج شنبه 31 فروردین 1391, 19:42 عصر
AutoResetEvent read = new AutoResetEvent(false);

AutoResetEvent

چیه
چه کاربردی داره
کجا بکار می ره
یه مثالی میشه بزنید
تشکر

این مثال شاید مفید باشه برای شما :

Imports System.Threading
Public Class Form1
Private autoEvent As AutoResetEvent = New AutoResetEvent(False)
Dim check As Boolean = False
Private Sub ThreadA()
If Me.InvokeRequired Then
Invoke(New MethodInvoker(AddressOf ThreadA), Nothing)
Else
Me.Label1.Text = "Thread A started"
For i = 0 To 1000000
Application.DoEvents()
Me.ProgressBar1.Value = i
Next
End If
autoEvent.Set() 'باید خط آخر باشد
End Sub
Private Sub ThreadB()
autoEvent.WaitOne()
If Me.InvokeRequired Then
Invoke(New MethodInvoker(AddressOf ThreadB), Nothing)
Else
Me.Label1.Text = "Thread B started"
For i = 0 To 1000000
Application.DoEvents()
Me.ProgressBar2.Value = i
Next

End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ta As New Threading.Thread(AddressOf ThreadA)
ta.Start()

Dim tb As New Threading.Thread(AddressOf ThreadB)
tb.Start()
End Sub
End Class

amirzandi
پنج شنبه 31 فروردین 1391, 19:48 عصر
این هم حالتی که تعداد Thread های شما از 2 تا بیشتر باشد :


Imports System.Threading
Public Class Form1
Private autoEvent As AutoResetEvent = New AutoResetEvent(False)
Private autoEvent1 As AutoResetEvent = New AutoResetEvent(False)
Dim check As Boolean = False
Private Sub ThreadA()
If Me.InvokeRequired Then
Invoke(New MethodInvoker(AddressOf ThreadA), Nothing)
Else
Me.Label1.Text = "Thread A started"
For i = 0 To 1000000
Application.DoEvents()
Me.ProgressBar1.Value = i
Next
End If
autoEvent.Set() 'باید خط آخر باشد
End Sub
Private Sub ThreadB()
autoEvent.WaitOne()
If Me.InvokeRequired Then
Invoke(New MethodInvoker(AddressOf ThreadB), Nothing)
Else
Me.Label1.Text = "Thread B started"
For i = 0 To 1000000
Application.DoEvents()
Me.ProgressBar2.Value = i
Next
End If
autoEvent1.Set()
End Sub
Private Sub ThreadC()
autoEvent1.WaitOne()
If Me.InvokeRequired Then
Invoke(New MethodInvoker(AddressOf ThreadC), Nothing)
Else
Me.Label1.Text = "Thread C started"
For i = 0 To 1000000
Application.DoEvents()
Me.ProgressBar3.Value = i
Next
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ta As New Threading.Thread(AddressOf ThreadA)
ta.Start()

Dim tb As New Threading.Thread(AddressOf ThreadB)
tb.Start()

Dim tc As New Threading.Thread(AddressOf ThreadC)
tc.Start()
End Sub
End Class