Example #1
0
        public GitAsyncOperation QueueWorker <T>(Action <T> waitCallback, T state, string name, Action <GitAsyncOperation> onComplete, bool threaded)
        {
            var operation = new GitAsyncOperationComplex <T>(string.IsNullOrEmpty(name) ? GUID.Generate().ToString() : name, waitCallback, state);

            if (onComplete != null)
            {
                operation.onComplete += onComplete;
            }

            if (threaded && ThreadPool.QueueUserWorkItem(p =>
            {
                try
                {
                    waitCallback.Invoke((T)p);
                }
                finally
                {
                    operation.MarkDone();
                }
            }, state))
            {
                lock (activeOperations)
                {
                    activeOperations.Add(operation);
                }
            }
            else
            {
                operation.Invoke(operation.State);
            }
            return(operation);
        }
Example #2
0
        public GitAsyncOperation QueueWorkerWithLock <T>(Action <T> waitCallback, T state, string name, Action <GitAsyncOperation> onComplete, object lockObj, bool threaded)
        {
            var operation = new GitAsyncOperationComplex <T>(string.IsNullOrEmpty(name) ? Guid.NewGuid().ToString() : name, waitCallback, state);

            if (onComplete != null)
            {
                operation.onComplete += onComplete;
            }

            if (threaded && ThreadPool.QueueUserWorkItem(p =>
            {
                Monitor.Enter(lockObj);
                try
                {
                    operation.Invoke(p);
                }
                finally
                {
                    Monitor.Exit(lockObj);
                }
            }, state))
            {
                lock (activeOperations)
                {
                    activeOperations.Add(operation);
                }
            }
            else
            {
                operation.Invoke(operation.State);
            }
            return(operation);
        }