|
-
Sep 25th, 2003, 05:44 PM
#1
Thread Starter
Member
check if application duplicate
hi again,
i know i've been posting alot today, but i am close to finishing my first .net application so i need to put in a few final touches.
how can i allow windows to run only one 'instance' of my program? that is, while program running, user cannot execute exe file of the program....
thanks
-
Sep 25th, 2003, 05:58 PM
#2
Try searching for 'single instance' on this forums. This question comes up frequently. In fact you should always try a search before posting if you want to save sometime. Lastly if you find multiple examples pick the one that uses a Mutex it'll be faster. In fact here I'll do the search for ya: http://www.vbforums.com/search.php?s...der=descending
-
Sep 25th, 2003, 06:22 PM
#3
Thread Starter
Member
-
Sep 26th, 2003, 12:05 PM
#4
Sleep mode
Yes , always do a search boy
This was copied from VBCodeBook , you know that guys 
VB Code:
Check for multiple instances of a program and ask the user if he / she wants to run another copy.
'Create a new instance of your main form
Dim MainForm As New Form1()
Private Sub MultiCheck()
'Get number of processes of you program
If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
'Ask user if they want to run another copy
If MessageBox.Show("There is already a copy of this program." & vbCrLf _
& "Do you want to launch another?.", _
"Launch another copy of this program?", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1) = DialogResult.No Then
'If no, then exit the new instance of the program
Application.Exit()
Exit Sub
Else
'Else run the new program
MainForm.ShowDialog()
Exit Sub
End If
End If
'If this is the only one, run it!
MainForm.ShowDialog()
End Sub
-
Sep 26th, 2003, 12:24 PM
#5
I used to use that same process but the Mutex way is much faster, like 10 times faster.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|