How to open only one instance of an application?
-
Dear all, i'm an ASp.net developer but i'm workin on a desktop application There is a requirement that is to open only one executable of the application and if the user tries to open another instance the application returns an error message So how can i know that there is an instance already running? One of the thoughts was to create a state variable saved in a text file or xml file but u cann't manage it 100% because maybe the OS restarted or the user closes the application by killing the process... So i think there is a better way by checking running prcesses in the memory. Any key how can i implement that? P.S. I'm using VB script on VS.net 2003
Best Regards 3ala2 :)
-
Dear all, i'm an ASp.net developer but i'm workin on a desktop application There is a requirement that is to open only one executable of the application and if the user tries to open another instance the application returns an error message So how can i know that there is an instance already running? One of the thoughts was to create a state variable saved in a text file or xml file but u cann't manage it 100% because maybe the OS restarted or the user closes the application by killing the process... So i think there is a better way by checking running prcesses in the memory. Any key how can i implement that? P.S. I'm using VB script on VS.net 2003
Best Regards 3ala2 :)
-
Dear all, i'm an ASp.net developer but i'm workin on a desktop application There is a requirement that is to open only one executable of the application and if the user tries to open another instance the application returns an error message So how can i know that there is an instance already running? One of the thoughts was to create a state variable saved in a text file or xml file but u cann't manage it 100% because maybe the OS restarted or the user closes the application by killing the process... So i think there is a better way by checking running prcesses in the memory. Any key how can i implement that? P.S. I'm using VB script on VS.net 2003
Best Regards 3ala2 :)
Try this :-
Dim currentProcess As Process = Process.GetCurrentProcess() Dim allProcesses() As Process = Process.GetProcessesByName(currentProcess.ProcessName) If allProcesses.Length > 1 Then Me.Opacity = 0.5 MessageBox.Show("Program already running. This session will close") Application.Exit() End If
Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
-
Try this :-
Dim currentProcess As Process = Process.GetCurrentProcess() Dim allProcesses() As Process = Process.GetProcessesByName(currentProcess.ProcessName) If allProcesses.Length > 1 Then Me.Opacity = 0.5 MessageBox.Show("Program already running. This session will close") Application.Exit() End If
Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'