Meanie Posted April 8, 2003 Posted April 8, 2003 The following is the code I use to prevent multiple instances of my app. Its the same code I used from a previous thread on this forum Public Class Initialise Shared Sub Main() ' Prevent Multiple Instances of the Application Dim appProcesses As Process() appProcesses = Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName) If appProcesses.Length > 1 Then Application.Exit() Else Dim formMain = New frmMain() Application.Run(formMain) End If End Sub End Class Now the thing is, this all used to work up until last night. Now whenever I compile my app I get the following error message An unhandled exception of type 'System.InvalidOperationException' occurred in system.dll Additional information: Process performance counter is disabled, so the requested operation cannot be performed. This refers to this line appProcesses = Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName) Now I don't recall disabling the process performance counter, or whatever it is. Any ideas on how to fix this? Quote
*Gurus* Derek Stone Posted April 8, 2003 *Gurus* Posted April 8, 2003 [mshelp]ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemThreadingMutexClassTopic.htm[/mshelp] Quote Posting Guidelines
Meanie Posted April 9, 2003 Author Posted April 9, 2003 Okay, so this is meant to help multiple threads share resources, right? It doesn't really help my situation because I can't even get one thread running thanks to my compile error. ADDITIONAL: I loaded up an earlier version of my code, ran it once, and got the exact same error as the newer version. And this was *working* code. I think a windows setting got changed or something as I was writing the update to my code, because I know my computer was having a few fits when I did a compile once. Quote
*Gurus* Derek Stone Posted April 9, 2003 *Gurus* Posted April 9, 2003 Dim m As Mutex = New Mutex(False, "ApplicationName") If Not m.WaitOne(0, False) Then 'Application is already running End If Quote Posting Guidelines
Meanie Posted April 10, 2003 Author Posted April 10, 2003 Thanks, that works. Though I still don't get why my old code decided to stop working (both versions of it) Quote
Darren66 Posted July 26, 2003 Posted July 26, 2003 I have been using the code that Derek posted here some time ago to check for multiple instances of my application however it seems that although it works perfectly in Debug Configuration when I switch to Release Configuration it stops working... Has anyone else noticed this or is it just my machine!! Cheers Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.