本文整理汇总了C#中System.Threading.Task.OnTaskStarted方法的典型用法代码示例。如果您正苦于以下问题:C# Task.OnTaskStarted方法的具体用法?C# Task.OnTaskStarted怎么用?C# Task.OnTaskStarted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Task
的用法示例。
在下文中一共展示了Task.OnTaskStarted方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteTask
private void ExecuteTask(Task task)
{
currentTask = task;
Power.ExecutionState = ExecutionState.Continuous | ExecutionState.SystemRequired;
try
{
task.Canceled = false;
task.OnTaskStarted();
foreach (ErasureTarget target in task.Targets)
try
{
UnusedSpaceTarget unusedSpaceTarget =
target as UnusedSpaceTarget;
FileSystemObjectTarget fileSystemObjectTarget =
target as FileSystemObjectTarget;
if (unusedSpaceTarget != null)
EraseUnusedSpace(task, unusedSpaceTarget);
else if (fileSystemObjectTarget != null)
EraseFilesystemObject(task, fileSystemObjectTarget);
else
throw new ArgumentException("Unknown erasure target.");
}
catch (FatalException)
{
throw;
}
catch (OperationCanceledException)
{
throw;
}
catch (ThreadAbortException)
{
}
catch (Exception e)
{
Logger.Log(e.Message, LogLevel.Error);
BlackBox.Get().CreateReport(e);
}
}
catch (FatalException e)
{
Logger.Log(e.Message, LogLevel.Fatal);
}
catch (OperationCanceledException e)
{
Logger.Log(e.Message, LogLevel.Fatal);
}
catch (ThreadAbortException)
{
}
catch (Exception e)
{
Logger.Log(e.Message, LogLevel.Error);
BlackBox.Get().CreateReport(e);
}
finally
{
Power.ExecutionState = ExecutionState.Continuous;
if (task.Schedule is RecurringSchedule)
((RecurringSchedule)task.Schedule).Reschedule(DateTime.Now);
if (task.Schedule == Schedule.RunOnRestart)
task.Schedule = Schedule.RunNow;
task.OnTaskFinished();
currentTask = null;
}
}