Click here to Skip to main content
       

.NET Framework

 
AnswerRe: spawning mmc to a particular server or hosting remote console in an application PinmvpDave Kreskowiak7-Mar-13 3:33 
AnswerRe: spawning mmc to a particular server or hosting remote console in an application PinmemberMartin-FFB14-Apr-13 23:57 
AnswerRe: spawning mmc to a particular server or hosting remote console in an application Pinmembergaraber30-Apr-13 14:04 
QuestionCrystal Report Selection Formula PinmemberNeeraj86624-Mar-13 21:30 
Questionc# PinmemberK.Bharathidhasan1-Mar-13 3:03 
AnswerRe: c# PinmemberThePhantomUpvoter1-Mar-13 4:00 
AnswerRe: c# PinmvpEddy Vluggen1-Mar-13 4:00 
AnswerRe: c# Pinmember ProgramFOX3-Mar-13 7:17 
QuestionI want to store webservice method's XML output as string in C# PinmemberMember 982628125-Feb-13 1:21 
AnswerRe: I want to store webservice method's XML output as string in C# PinmvpEddy Vluggen25-Feb-13 9:20 
AnswerRe: I want to store webservice method's XML output as string in C# Pinmemberjschell25-Feb-13 10:01 
Question[VB.NET 2008] Compact Framework: how to start a single instance of an application Pinmembersteve_949661325-Feb-13 0:28 
AnswerRe: [VB.NET 2008] Compact Framework: how to start a single instance of an application PinmvpEddy Vluggen25-Feb-13 9:10 
GeneralRe: [VB.NET 2008] Compact Framework: how to start a single instance of an application Pinmembersteve_949661326-Feb-13 0:44 
Hi Eddy!
Searching again I found some code about mutex and with little changes it seems to work.
I wrote (copy/past + some changes...) a class SingleInstanceApplication:
 
Imports System.Reflection
Imports System.Runtime.InteropServices
 
Public Class SingleInstanceApplication
 
  <DllImport("Coredll.dll", SetLastError:=True)> _
  Public Shared Function CreateMutex(ByVal Attr As IntPtr, ByVal Own As Boolean, ByVal Name As String) As IntPtr
  End Function
 
  <DllImport("Coredll.dll", SetLastError:=True)> _
  Public Shared Function ReleaseMutex(ByVal hMutex As IntPtr) As Boolean
  End Function
 
  Const ERROR_ALREADY_EXISTS As Long = 183
 
  Public Shared Sub Run(ByVal frm As Form)
    Dim name As String = Assembly.GetExecutingAssembly().GetName().Name
    Dim mutexHandle As IntPtr = CreateMutex(IntPtr.Zero, True, name)
    Dim Rerror As Long = Marshal.GetLastWin32Error()
 
    'MessageBox.Show(name & " - " & mutexHandle.ToString & " - " & Rerror.ToString)  'just for debug

    If (Not Rerror = ERROR_ALREADY_EXISTS) Then
      Application.Run(frm)
    End If
 
    'MessageBox.Show("release mutex")  'just for debug

    ReleaseMutex(mutexHandle)
 
  End Sub
End Class
 
then I wrote a class to start the application:
 
Public Class StartApp
  Public Shared Sub main()
    Try
      SingleInstanceApplication.Run(FormMain)
    Catch ex As Exception
      MessageBox.Show(ex.Message)
    End Try
  End Sub
End Class
 
finally I modified the start object of the application from "FormMain" (the main form of the application) to "StartApp".
It works!
 
Thanks.
GeneralRe: [VB.NET 2008] Compact Framework: how to start a single instance of an application PinmvpEddy Vluggen26-Feb-13 1:33 
QuestionEvent Handling between Threads PinmemberAeroClassics19-Feb-13 12:37 
AnswerRe: Event Handling between Threads PinmemberGerry Schmitz19-Feb-13 20:25 
GeneralRe: Event Handling between Threads PinmemberAeroClassics20-Feb-13 5:45 
QuestionWays of implenting IEnumerable in VB PinmemberMike-MadBadger19-Feb-13 12:10 
AnswerRe: Ways of implenting IEnumerable in VB PinmemberMicroVirus13-Mar-13 12:56 
GeneralRe: Ways of implenting IEnumerable in VB PinmemberMike-MadBadger13-Mar-13 22:44 
Questionhow to manage exicution code Pinmembernanhesab18-Feb-13 1:58 
AnswerRe: how to manage exicution code PinmvpEddy Vluggen18-Feb-13 2:01 
AnswerRe: how to manage exicution code PinmemberSuper Lloyd18-Feb-13 2:33 
AnswerRe: how to manage exicution code PinmvpSandeep Mewara18-Feb-13 4:13 
Questionharvesting social images for bi concept image search Pinmemberkrish888817-Feb-13 17:32 
AnswerRe: harvesting social images for bi concept image search PinmemberN a v a n e e t h17-Feb-13 18:13 
AnswerRe: harvesting social images for bi concept image search PinmvpSandeep Mewara17-Feb-13 19:24 
AnswerRe: harvesting social images for bi concept image search PinmvpAbhinav S19-Feb-13 1:08 
AnswerRe: harvesting social images for bi concept image search PinmvpDave Kreskowiak19-Feb-13 2:45 
QuestionWhere to get Regasm and Gacutil? Pinmembercjb11015-Feb-13 1:54 
AnswerRe: Where to get Regasm and Gacutil? PinmemberRichard Deeming15-Feb-13 2:01 
GeneralRe: Where to get Regasm and Gacutil? Pinmembercjb11015-Feb-13 3:55 
AnswerRe: Where to get Regasm and Gacutil? PinmvpDave Kreskowiak15-Feb-13 3:12 
GeneralRe: Where to get Regasm and Gacutil? Pinmembercjb11015-Feb-13 3:48 
QuestionWeb development using C++ PinmemberAseelHadlaq15-Feb-13 0:04 
AnswerRe: Web development using C++ PinmemberN a v a n e e t h15-Feb-13 0:47 
AnswerRe: Web development using C++ PinmvpDave Kreskowiak15-Feb-13 3:04 
AnswerRe: Web development using C++ PinmemberMarco Bertschi15-Feb-13 4:27 
GeneralRe: Web development using C++ Pinmemberkrysiaaa15-Feb-13 6:44 
AnswerRe: Web development using C++ Pinmemberjschell15-Feb-13 10:11 
AnswerRe: Web development using C++ PinmvpRahul Rajat Singh17-Feb-13 19:43 
QuestionUSB Barcode scanner in C# PinmemberMember 830583814-Feb-13 23:15 
AnswerRe: USB Barcode scanner in C# PinmvpDave Kreskowiak15-Feb-13 3:05 
GeneralRe: USB Barcode scanner in C# PinmemberMember 830583815-Feb-13 4:00 
GeneralRe: USB Barcode scanner in C# PinmvpDave Kreskowiak15-Feb-13 4:33 
GeneralMessage Removed PinmemberMember 984580018-Feb-13 20:33 
GeneralRe: USB Barcode scanner in C# PinmvpDave Kreskowiak19-Feb-13 2:44 
QuestionwinRT xaml/C# listview selected index PinmemberClodetta del Mar14-Feb-13 5:38 
AnswerRe: winRT xaml/C# listview selected index PinmemberMarco Bertschi15-Feb-13 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 17 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid