Only one instance of an application

C

Code Monkey

I know one varient of this question has been posted a lot, but this
seems to be slighlty different.

I've got the following code in my application

<code>

[STAThread]
private static void Main()
{
bool createdNew;
string process_name =
Process.GetCurrentProcess().ProcessName.ToString();
Mutex m = new Mutex(true, process_name, out createdNew);
if (!createdNew)
{
return;
}
Application.Run(new Form1());

GC.KeepAlive(m);
}
</code>

whilst this works fine for a user logged onto a machine, it does NOT
work across multiple RDP connections.

Is it possible to detect if another user has already started an
application in another session? Or would I be better moving the entire
application into a service (its an order processing application) and
just displaying the GUI of the application to the user who attempts to
'start' the application?
 
J

Jon Skeet [C# MVP]

Code said:
I know one varient of this question has been posted a lot, but this
seems to be slighlty different.

whilst this works fine for a user logged onto a machine, it does NOT
work across multiple RDP connections.

Is it possible to detect if another user has already started an
application in another session? Or would I be better moving the entire
application into a service (its an order processing application) and
just displaying the GUI of the application to the user who attempts to
'start' the application?

I believe it depends on the name of the mutex. If you name the mutex
"Global\[...]" then I *believe* it should work. It's then scoped for
the whole machine, rather than that particular login.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top