Пример #1
0
        protected T ExecuteInSemaphore <T>(Func <T> func, string methodName, bool invalidateDrive = false)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }

            _semaphore.Wait();
            try
            {
                return(func());
            }
            catch (AggregateException ex) when(ex.InnerExceptions.Count == 1)
            {
                throw ex.InnerExceptions[0];
            }
            finally
            {
                if (invalidateDrive)
                {
                    _drive = null;
                }
                _semaphore.Release();
            }
        }
Пример #2
0
        protected void ExecuteInSemaphore(Action action, string methodName, bool invalidateDrive = false)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            _semaphore.Wait();
            try
            {
                action();
            }
            catch (AggregateException ex) when(ex.InnerExceptions.Count == 1)
            {
                throw ex.InnerExceptions[0];
            }
            finally
            {
                if (invalidateDrive)
                {
                    _drive = null;
                }
                _semaphore.Release();
            }
        }
 protected void InvalidateDrive()
 {
     drive = null;
 }