Exemplo n.º 1
0
        public static GitAsyncOperation QueueWorker(Action waitCallback, string name, Action <GitAsyncOperation> onComplete)
        {
            var operation = GitAsyncOperation.Create(string.IsNullOrEmpty(name) ? GUID.Generate().ToString() : name, onComplete);

            ThreadPool.QueueUserWorkItem((c) =>
            {
                waitCallback.Invoke();
                operation.MarkDone();
            });

            return(operation);
        }
Exemplo n.º 2
0
        public GitAsyncOperation QueueWorkerWithLock(Action waitCallback, string name, Action <GitAsyncOperation> onComplete, object lockObj)
        {
            var operation = GitAsyncOperation.Create(string.IsNullOrEmpty(name) ? GUID.Generate().ToString() : name);

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

            if (!ThreadPool.QueueUserWorkItem((c) =>
            {
                Monitor.Enter(lockObj);
                try
                {
                    waitCallback.Invoke();
                }
                finally
                {
                    operation.MarkDone();
                    Monitor.Exit(lockObj);
                }
            }))
            {
                ShowUnableToQueueError(name);
                try
                {
                    waitCallback.Invoke();
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
                finally
                {
                    operation.MarkDone();
                    operation.Complete();
                }
            }
            else
            {
                activeOperations.Add(operation);
            }
            return(operation);
        }
Exemplo n.º 3
0
        public GitAsyncOperation QueueWorker <T>(Action <T> waitCallback, T state, string name, Action <GitAsyncOperation> onComplete)
        {
            var operation = GitAsyncOperation.Create(string.IsNullOrEmpty(name) ? GUID.Generate().ToString() : name);

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

            if (!ThreadPool.QueueUserWorkItem(p =>
            {
                try
                {
                    waitCallback.Invoke((T)p);
                }
                finally
                {
                    operation.MarkDone();
                }
            }, state))
            {
                ShowUnableToQueueError(name);
                try
                {
                    waitCallback.Invoke(state);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
                finally
                {
                    operation.MarkDone();
                    operation.Complete();
                }
            }
            else
            {
                activeOperations.Add(operation);
            }
            return(operation);
        }