现在有2个类 我想实现 把task的线程放到ThreadGroup里,然后自己阻塞,等ThreadGroup来叫醒他,现在的问题是.net里的sleep是类方法,我这么实现不行啊,java里我是wait,然后notify的。
Imports System.Threading
Public Class ThreadGroup Private Shared threads As ArrayList
Public Shared Sub StartThreads() For Each tt As Thread In threads
tt.Interrupt()
threads.Remove(tt) Next
End Sub
Public Shared Sub AddThread(ByRef tt As Thread)
threads.Add(tt)
End SubEnd Class
/***********************************************************************************/
Imports System.Threading
Public Class Task Public Sub DoTask()
ThreadGroup.AddThread(Threading.thread.currentThread)
Try
Thread.Sleep(Timeout.Infinite)
Catch ex As Exception End Try
End SubEnd Class
Imports System.Threading
Public Class ThreadGroup Private Shared threads As ArrayList
Public Shared Sub StartThreads() For Each tt As Thread In threads
tt.Interrupt()
threads.Remove(tt) Next
End Sub
Public Shared Sub AddThread(ByRef tt As Thread)
threads.Add(tt)
End SubEnd Class
/***********************************************************************************/
Imports System.Threading
Public Class Task Public Sub DoTask()
ThreadGroup.AddThread(Threading.thread.currentThread)
Try
Thread.Sleep(Timeout.Infinite)
Catch ex As Exception End Try
End SubEnd Class
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货