本文整理汇总了C#中ITask.Cancel方法的典型用法代码示例。如果您正苦于以下问题:C# ITask.Cancel方法的具体用法?C# ITask.Cancel怎么用?C# ITask.Cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITask
的用法示例。
在下文中一共展示了ITask.Cancel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Cancel
/// <summary>
/// Cancels selected task.
/// </summary>
public void Cancel(ITask task, object reason)
{
if (task == null)
throw new ArgumentNullException("task");
task.Cancel(reason);
RemoveTask(task);
}
示例2: manageTask
private void manageTask(ITask value)
{
StartingTask.Raise(this, new TaskmanagerEventArgs() { Task = value });
TaskEntry entry;
if (QueuedTasks.TryGetValue(value.UniqueId, out entry))
{
if (entry.State == "pending")
{
Exception exception = null;
try
{
CurrentTasks.TryAdd(value.UniqueId, value);
TaskEntry s;
QueuedTasks.TryRemove(value.UniqueId, out s);
StartedTask.Raise(this, new TaskmanagerEventArgs() { Task = value });
value.Run();
}
catch (Exception ex)
{
exception = ex;
Log.Error(ex.ToString());
TaskEntry s;
QueuedTasks.TryRemove(value.UniqueId, out s);
s.State = "error";
s.Message = ex.ToString() + "\n " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();
s.UniqueId = value.UniqueId;
s.Description = value.TaskDescription; ;
s.Name = value.Name;
s.TimeStamp = value.TimeStamp;
ProcessedTasks.TryAdd(s.UniqueId, s);
ITask irt;
CurrentTasks.TryRemove(s.UniqueId, out irt);
}
finally
{
var ea = new TaskmanagerEventArgs() { Task = value, Exception = exception };
EndingTask.Raise(this, ea);
TaskEntry s;
QueuedTasks.TryRemove(value.UniqueId, out s);
s.State = "completed";
s.Message = "Completed on: " + DateTime.Now.ToString();
s.UniqueId = value.UniqueId;
s.Name = value.Name;
s.Description = value.TaskDescription;
s.TimeStamp = value.TimeStamp;
ProcessedTasks.TryAdd(s.UniqueId, s);
ITask irt;
CurrentTasks.TryRemove(s.UniqueId, out irt);
if (exception == null)
value.End();
EndedTask.Raise(this, ea);
value.Dispose();
}
}
else
{
TaskEntry s;
QueuedTasks.TryRemove(value.UniqueId, out s);
ProcessedTasks.TryAdd(s.UniqueId, s);
value.Cancel();
}
}
}