如果已经运行,则阻止应用程序启动 [英] Prevent application launch if already running
问题描述
我的应用程序需要在启动时检查它是否已经在运行,以便它不会再次打开.我有一个系统托盘图标,可以使应用程序可见 = False.效果很好.然而,如果应用程序已经在运行,我需要确保用户查看系统托盘中的通知图标.
Private Sub mainWindowSmall_Load(sender As Object, e As EventArgs) 处理MyBase.LoadDim p() 作为进程p = Process.GetProcessesByName("TSC 工具箱")如果 p.Count >0 那么MessageBox.Show("TSC 工具箱已经在运行.检查系统托盘!", _警告!!!",MessageBoxButtons.OK,_MessageBoxIcon.Error, MessageBoxDefaultButton.Button2)我.Close()别的总加载()万一结束子
VB.NET |winforms
此功能已内置到 Windows 窗体中.只需转到项目属性并单击单实例应用程序"复选框.还有一个您可以处理的StartupNextInstance事件.>
My app needs to check and see if it is already running when launching so it doesn't open a second time. I have a system tray icon that can make the application visible = False. Works great. However, I need to make sure the user looks at the system tray for the notifyicon if the app is already running.
Private Sub mainWindowSmall_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim p() As Process
p = Process.GetProcessesByName("TSC Tool Box")
If p.Count > 0 Then
MessageBox.Show("The TSC Tool Box is already running. Check System tray!", _
"Warning !!!", MessageBoxButtons.OK, _
MessageBoxIcon.Error, MessageBoxDefaultButton.Button2)
Me.Close()
Else
totalOnLoad()
End If
End Sub
VB.NET | winforms
This feature is already built in to Windows Forms. Just go to the project properties and click the "Single Instance Application" checkbox. There's also a StartupNextInstance event that you can handle.
这篇关于如果已经运行,则阻止应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!