/// <summary> /// Create a ResourceMutex for the specified mutex id and resource-name /// </summary> /// <param name="mutexId">ID of the mutex, preferably a Guid as string</param> /// <param name="resourceName">Name of the resource to lock, e.g your application name, usefull for logs</param> /// <param name="global">true to have a global mutex see: https://msdn.microsoft.com/en-us/library/bwe34f1k.aspx </param> public static ResourceMutex Create(string mutexId, string resourceName = null, bool global = false) { if (mutexId == null) { throw new ArgumentNullException(nameof(mutexId)); } var applicationMutex = new ResourceMutex((global ? @"Global\" : @"Local\") + mutexId, resourceName); applicationMutex.Lock(); return(applicationMutex); }
/// <summary> /// Create the application bootstrapper, for the specified application name /// The mutex is created and locked in the contructor, and some of your application logic might depend on this. /// </summary> /// <param name="applicationName">Name of your application</param> /// <param name="mutexId"> /// string with an ID for your mutex, preferably a Guid. If the mutex can't be locked, the /// bootstapper will not be able to "bootstrap". /// </param> /// <param name="global">Is the mutex a global or local block (false means only in this Windows session)</param> public ApplicationBootstrapper(string applicationName, string mutexId = null, bool global = false) { if (applicationName == null) { throw new ArgumentNullException(nameof(applicationName)); } ApplicationName = applicationName; if (mutexId != null) { _resourceMutex = ResourceMutex.Create(mutexId, applicationName, global); } }
/// <summary> /// Create the application bootstrapper /// </summary> /// <param name="applicationConfig">ApplicationConfig with the complete configuration</param> public ApplicationBootstrapper(ApplicationConfig applicationConfig) { _applicationConfig = applicationConfig ?? throw new ArgumentNullException(nameof(applicationConfig)); Instance = this; if (Thread.CurrentThread.Name == null) { Thread.CurrentThread.Name = applicationConfig.ApplicationName; } if (applicationConfig.HasMutex) { _resourceMutex = ResourceMutex.Create(applicationConfig.Mutex, applicationConfig.ApplicationName, applicationConfig.UseGlobalMutex); } Resolver = new AssemblyResolver(_applicationConfig); }
/// <summary> /// Create a ResourceMutex for the specified mutex id and resource-name /// </summary> /// <param name="mutexId">ID of the mutex, preferably a Guid as string</param> /// <param name="resourceName">Name of the resource to lock, e.g your application name, usefull for logs</param> /// <param name="global">true to have a global mutex see: https://msdn.microsoft.com/en-us/library/bwe34f1k.aspx </param> public static ResourceMutex Create(string mutexId, string resourceName = null, bool global = false) { var applicationMutex = new ResourceMutex((global ? @"Global\" : @"Local\") + mutexId, resourceName); applicationMutex.Lock(); return applicationMutex; }