Only one app running in MAC?

Dani_S 3,786 Reputation points
2024-06-26T12:02:14.2933333+00:00

Hi,

Does this code work on MAC, only one app running ?

Thanks,

public partial class App : Application

{

 private static Mutex mutex = new Mutex(true, Assembly.GetEntryAssembly().GetName().Name);

 public App()

 {

     if (!mutex.WaitOne(TimeSpan.Zero, true))

     {

         Current.Quit();

         Environment.Exit(0);

     }
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,607 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,866 Reputation points
    2024-06-26T16:12:43.3166667+00:00

    not on any O/S. The .net Mutex instance is tried to the process, its basically a static variable.

    if a name string is passed, a system mutex is used and works.

    On windows you would use the NT named mutex. On MacOS you would use the named pthread mutexes. if you pass a string, .net uses O/S mutex.

    On MacOs the Desktop already defaults to one instance, but you can start a second via terminal. But rather than a named mutex it is better to use NSWorkspace which has a list of running applications.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.