Пример #1
0
        public SingleInstance(string name, bool ignoreCase = true)
        {
            NameOfMutant = $"SingleInstance_" + name._NonNullTrim();

            if (ignoreCase)
            {
                NameOfMutant = NameOfMutant.ToLowerInvariant();
            }

            lock (LockObj)
            {
                if (ProcessWideSingleInstanceHashSet.Contains(NameOfMutant))
                {
                    throw new ApplicationException($"The single instance is already existing with this process.");
                }

                MutantBase mb = MutantBase.Create(NameOfMutant, true);
                try
                {
                    mb.Lock(true);

                    Mutant = mb;
                }
                catch
                {
                    mb._DisposeSafe();
                    throw;
                }

                ProcessWideSingleInstanceHashSet.Add(NameOfMutant);
            }
        }
Пример #2
0
 public MutantWin32Impl(string name)
 {
     InternalName = @"Global\" + MutantBase.GenerateInternalName(name);
     MutexObj     = new Mutex(false, InternalName, out _);
 }
Пример #3
0
 public MutantWin32ForSingleInstanceImpl(string name)
 {
     InternalName = @"Global\si_" + MutantBase.GenerateInternalName(name);
 }
Пример #4
0
 public MutantUnixImpl(string name)
 {
     Filename = Path.Combine(Env.UnixMutantDir, MutantBase.GenerateInternalName(name) + Extension);
     IO.MakeDirIfNotExists(Env.UnixMutantDir);
 }