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
  1. Home
  2. General Programming
  3. C#
  4. Single instance app, file extension problem HELP!

Single instance app, file extension problem HELP!

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 3 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.
  • C Offline
    C Offline
    cdengler
    wrote on last edited by
    #1

    I have a serious problem. I only want ONE instance of my application running. So in the Main, I have Process aProcess = Process.GetCurrentProcess(); string aProcName = aProcess.ProcessName; if (Process.GetProcessesByName(aProcName).Length > 1) { Application.ExitThread(); } which may not be the most effecient means, but it works. Now the problem is, I have an associated extension (let's say .xyz) that brings up the application whenever someone clicks on a file with this extension. This works fine as well. The PROBLEM is, if an instance of the application is already open, and someone clicks on an .xyz extension, a new instance of the application is attempted and the code above stops it from running. What I WANT to do, is to either A) Somehow have the new instance pass the args from the .xyz file to any CURRENT running instance of the application and then shut itself down as in above OR B) Don't even open up a new instance at all, but rather have it so that somehow something checks first to see if there IS an instance running. There HAS to be some way to do this? HELP?

    H M 2 Replies Last reply
    0
    • C cdengler

      I have a serious problem. I only want ONE instance of my application running. So in the Main, I have Process aProcess = Process.GetCurrentProcess(); string aProcName = aProcess.ProcessName; if (Process.GetProcessesByName(aProcName).Length > 1) { Application.ExitThread(); } which may not be the most effecient means, but it works. Now the problem is, I have an associated extension (let's say .xyz) that brings up the application whenever someone clicks on a file with this extension. This works fine as well. The PROBLEM is, if an instance of the application is already open, and someone clicks on an .xyz extension, a new instance of the application is attempted and the code above stops it from running. What I WANT to do, is to either A) Somehow have the new instance pass the args from the .xyz file to any CURRENT running instance of the application and then shut itself down as in above OR B) Don't even open up a new instance at all, but rather have it so that somehow something checks first to see if there IS an instance running. There HAS to be some way to do this? HELP?

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      There are many ways, some of which we've discussed previously in this forum and that authors have written articles about on this site. You should search for a solution first. Here's a preset search for you: http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=single+instance+application[^]. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles]

      1 Reply Last reply
      0
      • C cdengler

        I have a serious problem. I only want ONE instance of my application running. So in the Main, I have Process aProcess = Process.GetCurrentProcess(); string aProcName = aProcess.ProcessName; if (Process.GetProcessesByName(aProcName).Length > 1) { Application.ExitThread(); } which may not be the most effecient means, but it works. Now the problem is, I have an associated extension (let's say .xyz) that brings up the application whenever someone clicks on a file with this extension. This works fine as well. The PROBLEM is, if an instance of the application is already open, and someone clicks on an .xyz extension, a new instance of the application is attempted and the code above stops it from running. What I WANT to do, is to either A) Somehow have the new instance pass the args from the .xyz file to any CURRENT running instance of the application and then shut itself down as in above OR B) Don't even open up a new instance at all, but rather have it so that somehow something checks first to see if there IS an instance running. There HAS to be some way to do this? HELP?

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        There's a nice framework for these tasks: Building Real World Applications[^] by Chris Anderson. Really makes things easy... mav

        C 1 Reply Last reply
        0
        • M mav northwind

          There's a nice framework for these tasks: Building Real World Applications[^] by Chris Anderson. Really makes things easy... mav

          C Offline
          C Offline
          cdengler
          wrote on last edited by
          #4

          Yes, unfortunately with the security changes in .NET 1.1 this is no longer allowed since the following error occurs... Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed

          M 1 Reply Last reply
          0
          • C cdengler

            Yes, unfortunately with the security changes in .NET 1.1 this is no longer allowed since the following error occurs... Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed

            M Offline
            M Offline
            mav northwind
            wrote on last edited by
            #5

            Sure, but that's easy to come by. Here's an article by Ingo Rammer[^] about the changes in .NET 1.1. One more thing, you'll have to override InitializeLifetimeService() to return null on the class being published for remoting or its lifetime lease will run out after approx. 2 minutes, meaning that you'll get an error when you start a second instance of your app after >2 minutes. I've already contacted Chris Anderson, but he doesn't plan to update his article :( Regards, mav

            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