Vb.net 在If语句中使用逻辑Or和线程
我在程序中使用多线程,我想创建一个按钮来检查是否有线程仍在运行。如果没有线程在后台运行,我希望按钮执行一个特定的任务,比如运行另一个线程 我在按钮上编写了以下代码:Vb.net 在If语句中使用逻辑Or和线程,vb.net,multithreading,Vb.net,Multithreading,我在程序中使用多线程,我想创建一个按钮来检查是否有线程仍在运行。如果没有线程在后台运行,我希望按钮执行一个特定的任务,比如运行另一个线程 我在按钮上编写了以下代码: If thread1 Or thread2 Or thread3 is Nothing Then thread2 = New Thread(AddressOf Me.thread2_engine) thread2.Start() Else If thread2.IsA
If thread1 Or thread2 Or thread3 is Nothing Then
thread2 = New Thread(AddressOf Me.thread2_engine)
thread2.Start()
Else If thread2.IsAlive = True Then
MsgBox("Processing right now, Please wait")
End If
为什么我不能在if语句中使用
或操作呢?如果使用或这样的语句,则对变量执行按位Or操作。我想你的意思是
If (thread1 Is Nothing) Or (thread2 Is Nothing) Or (thread3 Is Nothing) Then
您可能希望使用OrElse
而不是或
,因为这样可以避免在其中一个条件为真时检查后面的条件