基于这个问题,我决定根据 Jim Mischel 的建议尝试使用 waithandles/eventwaithandle 作为我的解决方案。我“几乎”让它工作。这是代码
Private Sub InitDeploymentCheck()
moDeploymentCheck = New TRS.Deployment.TRSDeploymentCheck(EnvironmentVariables.Environment, AppDomain.CurrentDomain.BaseDirectory.Contains("bin"), MDIMain)
AddHandler moDeploymentCheck.DeploymentNeeded,
Sub()
moTimer = New System.Windows.Forms.Timer()
moTimer.Interval = 300000 '5 minutes
moTimer.Enabled = True
AddHandler moTimer.Tick,
Sub()
'check to see if the message box exist or not before throwing up a new one
'check to see if the wait handle is non signaled, which means you shouldn't display the message box
If waitHandle.WaitOne(0) Then
'set handle to nonsignaled
waitHandle.Reset()
MessageBox.Show(MDIMain, "There is a recent critical deployment, please re-deploy STAR to get latest changes.", "Critical Deployment", MessageBoxButtons.OK, MessageBoxIcon.Warning)
'set the handle to signaled
waitHandle.Set()
End If
End Sub
waitHandle.Set()
MessageBox.Show(MDIMain, "There is a recent critical deployment, please re-deploy STAR to get latest changes.", "Critical Deployment", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Sub
End Sub
同样,这来自几乎我们所有应用程序都继承自的基本形式。当我们使用单个应用程序时,它可以完美运行。如果您运行多个从基本表单继承的应用程序并且有人仅单击一个消息框,则有时会在另一个应用程序中显示第二个消息框。我最初将等待句柄声明为静态/共享,并认为这是问题所在,但事实并非如此。我还尝试让每个应用程序创建自己的等待句柄并将其传递给基础,并产生相同的效果。有谁知道为什么看起来等待句柄在不同的应用程序之间共享?哦对了,waitHandle其实是一个ManualResetEvent