Preventing Multiple Instances no longer works

Meanie

Newcomer
Joined
Jan 4, 2003
Messages
23
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

Code:
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
Code:
        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?
 
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.
 
Thanks, that works.

Though I still don't get why my old code decided to stop working (both versions of it)
 
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
 
Back
Top