/// <summary> /// Creates a longrun task, and invokes action within /// </summary> /// <param name="method"></param> /// <param name="ID"></param> /// <param name="wait"></param> /// <returns></returns> public bool Run(Expression <Action> method, string ID, bool wait) { if (method == null) { return(false); } if (ID.IsNullOrEmpty()) { ID = Expressions.nameofFull(method); } if (ID.IsNullOrEmpty()) { return(false); } var task = Data.TryGetValue(ID, null); if (task != null && task.IsRunning) { if (wait) { task.Wait(); } else { return(false); } } this.Cleanup(); if (this.IsFull) { return(false); } lock (locker) { var task_new = Data.TryGetValue(ID, null); if (task_new != null && task_new.IsRunning) { return(false); } Action action = method.Compile(); TaskObject taskObject = new TaskObject(action); Data.Add(ID, taskObject, true); Data[ID].Run(); return(true); } }
public void JoinStop(string ID, int timeout_ms) { if (ID.IsNullOrEmpty()) { return; } TaskObject task = null; lock (locker) { task = Data.TryGetValue(ID, null); } if (task != null) { task.JoinStop(timeout_ms); } }