Create a VB.NET app that can be run in only one instance
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in D:\Hosting\3681091\html\blog\wp-content\plugins\digg-digg\dd.class.php on line 759
Warning: file_get_contents(http://feeds.delicious.com/v2/json/urlinfo/data?url=http%3A%2F%2Fwww.devtheweb.net%2Fblog%2F2010%2F03%2F11%2Fcreate-a-vb-net-app-that-can-be-run-in-only-one-instance%2F) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in D:\Hosting\3681091\html\blog\wp-content\plugins\digg-digg\dd.class.php on line 759
For some application you make want the user to be able to run only one of their instances (ex. an e-mail client). I found an easy way how it can be done.
If you are developing an VB.NET Windows Form application, first you will need to get the name of your main module and then to look for it in the collection of currently running processes. Here’s a simple example how it can be done:
Imports System.Diagnostics
…
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim moduleName As String = Diagnostics.Process.GetCurrentProcess.MainModule.ModuleName
Dim procName As String = System.IO.Path.GetFileNameWithoutExtension(moduleName)
If Process.GetProcessesByName(procName).Length > 1 Then
MessageBox.Show(“Already running”)
Application.Exit()
End If
End Sub
Well, that’s all :)

