Single instance app, file extension problem HELP!
-
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?
-
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?
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]
-
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?
There's a nice framework for these tasks: Building Real World Applications[^] by Chris Anderson. Really makes things easy... mav
-
There's a nice framework for these tasks: Building Real World Applications[^] by Chris Anderson. Really makes things easy... mav
-
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
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 returnnull
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