Esempio n. 1
0
        public GitAsyncOperation QueueWorkerWithLock(Action waitCallback, string name, Action <GitAsyncOperation> onComplete, object lockObj, bool threaded)
        {
            var operation = new GitAsyncOperationSimple(string.IsNullOrEmpty(name) ? Guid.NewGuid().ToString() : name, waitCallback);

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

            if (threaded && ThreadPool.QueueUserWorkItem((c) =>
            {
                Monitor.Enter(lockObj);
                try
                {
                    waitCallback.Invoke();
                }
                finally
                {
                    operation.MarkDone();
                    Monitor.Exit(lockObj);
                }
            }))
            {
                lock (activeOperations)
                {
                    activeOperations.Add(operation);
                }
            }
            else
            {
                operation.Invoke(operation.State);
            }

            return(operation);
        }
Esempio n. 2
0
        public GitAsyncOperation QueueWorker(Action waitCallback, string name, Action <GitAsyncOperation> onComplete, bool threaded)
        {
            var operation = new GitAsyncOperationSimple(string.IsNullOrEmpty(name) ? GUID.Generate().ToString() : name, waitCallback);

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

            if (threaded && ThreadPool.QueueUserWorkItem(operation.Invoke))
            {
                operation.Initialized = true;
            }

            lock (activeOperations)
            {
                activeOperations.Add(operation);
            }
            return(operation);
        }