Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SingleInstance" /> class and registers a <see cref="System.Threading.Mutex" /> and a WindowMessage using the specified identifier.
        /// </summary>
        /// <param name="identifier">A <see cref="string" /> representing the identifier for the <see cref="System.Threading.Mutex" /> and the WindowMessage.</param>
        public SingleInstance(string identifier)
        {
            Check.ArgumentNull(identifier, nameof(identifier));
            Check.ArgumentEx.StringNotEmpty(identifier, nameof(identifier));

            Mutex               = new Mutex(false, "BAPI_SINGLE_INSTANCE_" + identifier);
            Broadcast           = new HwndBroadcast("SINGLE_INSTANCE_" + identifier);
            Broadcast.Notified += Broadcast_Notified;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SingleInstance" /> class and registers a <see cref="System.Threading.Mutex" /> and a WindowMessage using the specified identifier.
        /// </summary>
        /// <param name="identifier">A <see cref="string" /> representing the identifier for the <see cref="System.Threading.Mutex" /> and the WindowMessage.</param>
        public SingleInstance(string identifier)
        {
            Check.ArgumentNull(identifier, nameof(identifier));
            Check.ArgumentEx.StringNotEmpty(identifier, nameof(identifier));

            Mutex               = new Mutex(false, "BAPI_SINGLE_INSTANCE_" + identifier);
            Broadcast           = new HwndBroadcast("BAPI_SINGLE_INSTANCE_BROADCAST_" + identifier);
            Broadcast.Notified += Broadcast_Notified;

            PipeName       = "BAPI_SINGLE_INSTANCE_PIPE_" + identifier;
            Pipe           = new NamedPipeServerStream(PipeName, PipeDirection.In, NamedPipeServerStream.MaxAllowedServerInstances);
            PipeThread     = ThreadFactory.StartThread(PipeThreadFunc);
            PipeIdentifier = MathEx.RandomNumberGenerator.GetInt32();
        }