Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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.

  • 3 months later...
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...