Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Application Opening again and again

Application Opening again and again

Scheduled Pinned Locked Moved C#
help
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MathewPV
    wrote on last edited by
    #1

    hello i am working in windows application the problem is when I execute the exe file the application executes. Without closing the application again i try to execute the exe file my application executes. I cannot let it happen.. Kindly give some ideas so that i can rectify the problem

    V G L 3 Replies Last reply
    0
    • M MathewPV

      hello i am working in windows application the problem is when I execute the exe file the application executes. Without closing the application again i try to execute the exe file my application executes. I cannot let it happen.. Kindly give some ideas so that i can rectify the problem

      V Offline
      V Offline
      vivasaayi
      wrote on last edited by
      #2

      In the Main method, Use Process class to determine if an instance of your program is already running. If running then display an Error Message and Close. Otherwise start the Application. USe the following method to test if the application is running.

      public static bool IsProcessOpen(string name)
      {
      foreach (Process clsProcess in Process.GetProcesses())
      {
      if (clsProcess.ProcessName.Contains(name))
      {
      return true;
      }
      }
      return false;
      }

      1 Reply Last reply
      0
      • M MathewPV

        hello i am working in windows application the problem is when I execute the exe file the application executes. Without closing the application again i try to execute the exe file my application executes. I cannot let it happen.. Kindly give some ideas so that i can rectify the problem

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        You can scan a list of processes but if someone renames the executable file that will not work. On the other hand using a mutex is much more reliable way of checking.

        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

        1 Reply Last reply
        0
        • M MathewPV

          hello i am working in windows application the problem is when I execute the exe file the application executes. Without closing the application again i try to execute the exe file my application executes. I cannot let it happen.. Kindly give some ideas so that i can rectify the problem

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, use a Mutex to make your app "single instance". There are several CP articles on the subject, here is one[^] of them. BTW: do not rely on process names, since they may be changed, and you might not get access to all of them. :)

          Luc Pattyn


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups