single-instance

How to implement single instance per machine application?

时间秒杀一切 提交于 2019-11-28 01:00:05
I have to restrict my .net 4 WPF application so that it can be run only once per machine. Note that I said per machine, not per session. I implemented single instance applications using a simple mutex until now, but unfortunately such a mutex is per session. Is there a way to create a machine wide mutex or is there any other solution to implement a single instance per machine application? I would do this with a global Mutex object that must be kept for the life of your application. MutexSecurity oMutexSecurity; //Set the security object oMutexSecurity = new MutexSecurity(); oMutexSecurity

Restrict multiple instances of an application in java

ⅰ亾dé卋堺 提交于 2019-11-27 15:39:13
I want to prevent multiple instances of application being launched in java. I know 2 methods for this: locking file locking socket But which is one is more efficient and good to use? Which one should I use? Any other solution to do the same are also welcome. EDIT: I tried that with Win200864b(version isn't important) and alive JFrame and move toFront() or Iconified in SystemTray with JFrame.DO_NOTHING_ON_CLOSE public interface ApplicationStartedListener { void applicationStarted(); void foreignApplicationStarted(String name); void messageArrived(Object obj); } // import java.io.Serializable;

How to check if a WPF application is already running? [duplicate]

℡╲_俬逩灬. 提交于 2019-11-27 15:03:01
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What is the correct way to create a single instance application? How can I check if my application is already open? If my application is already running, I want to show it instead of opening a new instance. 回答1: [DllImport("user32.dll")] private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow); static void Main() { Process currentProcess = Process.GetCurrentProcess(); var runningProcess = (from

onActivityResult do not fire if launch mode of activity is singleInstance

随声附和 提交于 2019-11-27 12:05:23
I have an Activity which is basically my main activity and its launch mode is single instance. But because of singleInstance, the onActivityResult() callback does not fire. And if I change the launch mode in my manifest file to any other mode it works fine. Can you explain why this callback is not working? Pedro Loureiro I believe that the problem is that singleInstance doesn't let the callee activity to exist in the same task as the caller, hence it can't return the value to the caller. Consider using singleTask instead: singleTask The system creates the activity at the root of a new task and

Let gVim always run a single instance

非 Y 不嫁゛ 提交于 2019-11-27 09:41:23
问题 Is there a way to let gVim only run a single instance, so that when a new file is opened with it it's automatically opened in a new tab in the currently running instance? I know you can do that by passing --remote-tab-silent but I want to configure gvim so that this becomes the default behavior. i.e. I want to type gvim filename and make it act as if I passed the --remote-tab-silent option to it. gVim 7.2 Edit I'm on windows (vista) 回答1: If you are using the bash shell (on Linux/OS X/using

How to run one instance of a c# WinForm application?

你离开我真会死。 提交于 2019-11-27 06:19:30
问题 I've a C# application that displays a login form when launched and displays the main form after users are authenticated. I used Mutex to restrict that only one instance of my application runs. And, this works fine for only the Login form. Once the main form is displayed, it doesn't restrict users from reopening the Login form. I was looking for a solution by which the Login screen couldn't be displayed once the main form is already opened. Here is my Program.cs [STAThread] static void Main()

Win32: How to get the process/thread that owns a mutex?

十年热恋 提交于 2019-11-27 02:23:15
问题 I'm working an application of which only one instance must exist at any given time. There are several possibilities to accomplish this: Check running processes for one matching our EXE's name (unreliable) Find the main window (unreliable, and I don't always have a main window) Create a mutex with a unique name (GUID) The mutex option seems to me the most reliable and elegant. However, before my second instance terminates, I want to post a message to the already running instance. For this, I

startActivityForResult not working properly with launchMode singleInstance

纵饮孤独 提交于 2019-11-27 01:56:19
问题 I'd like Activities on my application's Activity stack to only have one instance. I have several screens which are ListActivities and I'd like to not go through the pain and suffering of updating the lists in a previous instance of the ListActivity when another instance of that ListActivity is changed (added to, edited, removed from, etc) (or is there an easy way to do this?). Note: I've read that singleTop will accomplish this (though it destroys the Activity if you hit the back button), but

PyQt - how to detect and close UI if it's already running?

假如想象 提交于 2019-11-26 21:04:38
问题 I'm starting the UI from within Maya. If the UI hasn't been closed, running the UI again will completely freeze Maya (with the error "Event Loop is already running") Manually closing the UI before re-running the script will prevent it from freezing up. But I guess that's not really practical. Is there a way to detect if the UI I'm trying to run already exists? And possible force close it? 回答1: Here is a very simple PyQt5 solution using QLockFile: from PyQt5 import QtCore, QtWidgets lockfile =

How to create a single instance application in C or C++

瘦欲@ 提交于 2019-11-26 15:57:04
What would be your suggestion in order to create a single instance application, so that only one process is allowed to run at a time? File lock, mutex or what? Maxim Egorushkin A good way is: #include <sys/file.h> #include <errno.h> int pid_file = open("/var/run/whatever.pid", O_CREAT | O_RDWR, 0666); int rc = flock(pid_file, LOCK_EX | LOCK_NB); if(rc) { if(EWOULDBLOCK == errno) ; // another instance is running } else { // this is the first instance } Note that locking allows you to ignore stale pid files (i.e. you don't have to delete them). When the application terminates for any reason the