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); }
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); }
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); }