Beispiel #1
0
        internal ProcessLockScope(
            IProcessLock locks,
            string processName)
        {
            _locks       = locks;
            _processName = processName;

            Token = _locks.Create(_processName, LockDuration).GetAwaiter().GetResult();

            if (IsLocked)
            {
                _task = Run();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Coding4Fun.VisualStudio.ApplicationInsights.Channel.PersistenceTransmitter" /> class.
 /// </summary>
 /// <param name="storage">The transmissions storage.</param>
 /// <param name="sendersCount">The number of senders to create.</param>
 /// <param name="processLockFactory">IProcessLockBuilder that will create an IProcessLock to sync transmission between processes</param>
 /// <param name="createSenders">A boolean value that indicates if this class should try and create senders. This is a workaround for unit tests purposes only.</param>
 internal PersistenceTransmitter(StorageBase storage, int sendersCount, IProcessLockFactory processLockFactory, bool createSenders = true)
 {
     this.storage = storage;
     sendingCancellationTokenSource = new CancellationTokenSource();
     eventToKeepMutexThreadAlive    = new AutoResetEvent(false);
     try
     {
         string text = this.storage.StorageFolder?.FullName;
         if (text == null)
         {
             text = string.Empty;
         }
         locker = processLockFactory.CreateLocker(text, "_675531BB6E734D2F846AB8511A8963FD_");
     }
     catch (Exception ex)
     {
         locker = null;
         string message = string.Format(CultureInfo.InvariantCulture, "PersistenceTransmitter: Failed to construct the mutex: {0}", new object[1]
         {
             ex
         });
         CoreEventSource.Log.LogVerbose(message);
     }
     if (createSenders)
     {
         Task.Factory.StartNew(delegate
         {
             AcquireMutex(delegate
             {
                 CreateSenders(sendersCount);
             });
         }, TaskCreationOptions.LongRunning).ContinueWith(delegate(Task task)
         {
             string text2 = string.Format(CultureInfo.InvariantCulture, "PersistenceTransmitter: Unhandled exception in CreateSenders: {0}", new object[1]
             {
                 task.Exception
             });
             LocalFileLoggerService.Default.Log(LocalLoggerSeverity.Error, "Telemetry", text2);
             CoreEventSource.Log.LogVerbose(text2);
         }, TaskContinuationOptions.OnlyOnFaulted);
     }
 }