本文整理汇总了C#中ITask.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# ITask.Execute方法的具体用法?C# ITask.Execute怎么用?C# ITask.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITask
的用法示例。
在下文中一共展示了ITask.Execute方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueueTask
public void QueueTask(ITask task)
{
Task newTask = new Task(delegate () {
task.Execute();
});
newTask.RunSynchronously(this);
}
示例2: Execute
public TaskContext Execute(ITask task, object associatedData = null)
{
var context = new TaskContext(task, associatedData);
_dispatcher.BeginInvoke(() =>
{
_all.Add(task);
_contexts.Add(context);
UpdateBusy();
});
task.Execute(context).ContinueWith((p, d) =>
{
_dispatcher.BeginInvoke(() =>
{
_all.Remove(task);
_contexts.Remove(context);
UpdateBusy();
});
}).Failed((p, d) =>
{
});
return context;
}
示例3: Execute
public void Execute(ITask task, bool throwOnError = false)
{
JobsEventSource.Log.TaskExecuting(task.GetType().Name);
var startTime = DateTime.UtcNow;
try
{
task.Execute();
JobsEventSource.Log.TaskExecuted(task.GetType().Name, (DateTime.UtcNow - startTime).ToString());
}
catch (Exception ex)
{
JobsEventSource.Log.TaskExecutionError(task.GetType().Name, ex.GetType().Name, ex.Message, ex.StackTrace);
// Make sure the exception bubbles up and stops the execution of other tasks.
if (throwOnError)
throw;
}
}
示例4: ExecuteTask
private void ExecuteTask(ITask task)
{
try
{
_currentTask = task;
task.Execute(this);
}
catch (Exception ex)
{
var e = new TaskExceptionedEventArgs(this, task, ex);
Event.Invoke(UnhandledException, this, e);
// if the exception is not handled by external parties:
if (!e.Handled)
{
DebugLog.WriteCoreException(ex);
#if DEBUG
// this is not desired situation, so we hold the whole program!
Debugger.Break();
#endif
}
}
}
示例5: Enqueue
public override bool Enqueue(ITask task)
{
task.Execute ();
return true;
}
示例6: StartTask
private void StartTask(ITask task)
{
Task.Factory
.StartNew(() => task.Execute())
.ContinueWith(t => FinishTask(task));
}
示例7: Execute
public void Execute(ITask task)
{
task.Execute();
}
示例8: Step
internal void Step(ITask task, DispatcherQueue queue)
{
try {
if (iterator.MoveNext ()) {
task = iterator.Current;
task.LinkedIterator = this;
task.TaskQueue = queue;
task.Execute ();
}
} catch (Exception ex) {
this.iterator.Dispose ();
this.iterator = null;
Console.WriteLine (ex);
//TODO post it somewhere
}
}
示例9: RunTask
internal void RunTask(ITask task)
{
Exception excep = null;
try {
var obj = task.LinkedIterator;
var iter = task.Execute ();
if (obj != null && iter != null)
Console.WriteLine ("FIX ME PLEASE as I have a nested iterator");
if (iter != null) {
IteratorData id = new IteratorData (iter);
id.Begin (this);
}
if (obj != null)
((IteratorData)obj).Step (task, this);
} catch (Exception e) {
excep = e;
if (UnhandledException != null) {
UnhandledException (this, new UnhandledExceptionEventArgs (e, false));
excep = null;
}
var port = UnhandledExceptionPort;
if (port != null) {
port.Post (e);
excep = null;
}
} finally {
dispatcher.TaskDone (task, excep);
}
}
示例10: Enqueue
public override bool Enqueue(ITask task)
{
++count;
if (exec)
task.Execute ();
return true;
}
示例11: catch
/// <summary>
/// Do the work of actually instantiating and running the task.
/// </summary>
private OutOfProcTaskHostTaskResult InstantiateAndExecuteTask
(
IBuildEngine oopTaskHostNode,
LoadedType taskType,
string taskName,
string taskLocation,
string taskFile,
int taskLine,
int taskColumn,
AppDomainSetup appDomainSetup,
IDictionary<string, TaskParameter> taskParams
)
{
_taskAppDomain = null;
_wrappedTask = null;
try
{
_wrappedTask = TaskLoader.CreateTask(taskType, taskName, taskFile, taskLine, taskColumn, new TaskLoader.LogError(LogErrorDelegate), appDomainSetup, true /* always out of proc */, out _taskAppDomain);
Type wrappedTaskType = _wrappedTask.GetType();
_wrappedTask.BuildEngine = oopTaskHostNode;
}
catch (Exception e)
{
if (ExceptionHandling.IsCriticalException(e))
{
throw;
}
Exception exceptionToReturn = e;
// If it's a TargetInvocationException, we only care about the contents of the inner exception,
// so just save that instead.
if (e is TargetInvocationException)
{
exceptionToReturn = e.InnerException;
}
return new OutOfProcTaskHostTaskResult
(
TaskCompleteType.CrashedDuringInitialization,
exceptionToReturn,
"TaskInstantiationFailureError",
new string[] { taskName, taskLocation, String.Empty }
);
}
foreach (KeyValuePair<string, TaskParameter> param in taskParams)
{
try
{
PropertyInfo paramInfo = _wrappedTask.GetType().GetProperty(param.Key, BindingFlags.Instance | BindingFlags.Public);
paramInfo.SetValue(_wrappedTask, (param.Value == null ? null : param.Value.WrappedParameter), null);
}
catch (Exception e)
{
if (ExceptionHandling.IsCriticalException(e))
{
throw;
}
Exception exceptionToReturn = e;
// If it's a TargetInvocationException, we only care about the contents of the inner exception,
// so just save that instead.
if (e is TargetInvocationException)
{
exceptionToReturn = e.InnerException;
}
return new OutOfProcTaskHostTaskResult
(
TaskCompleteType.CrashedDuringInitialization,
exceptionToReturn,
"InvalidTaskAttributeError",
new string[] { param.Key, param.Value.ToString(), taskName }
);
}
}
bool success = false;
try
{
if (CancelPending)
{
return new OutOfProcTaskHostTaskResult(TaskCompleteType.Failure);
}
// If it didn't crash and return before now, we're clear to go ahead and execute here.
success = _wrappedTask.Execute();
}
catch (Exception e)
{
if (ExceptionHandling.IsCriticalException(e))
{
throw;
//.........这里部分代码省略.........
示例12: ExecuteCurrentTask
private IResult ExecuteCurrentTask(ITask currentTask, IResult previousResults, bool movingForward)
{
var performTask = PerformTask(currentTask, movingForward);
if (!performTask.Result)
{
Log.DebugFormat("Skipping task ({0}): {1}", currentTask.GetFriendlyName(), performTask.Reason);
return new SkipResult { SkipForward = movingForward };
}
Log.Task(currentTask);
var startTime = DateTime.UtcNow;
var result = currentTask.Execute(previousResults);
result.FromTask = currentTask;
DialogsManager.WaitForDurationOrCancel(
startTime,
new TimeSpan(0,0,0,currentTask.MinimumTaskTime));
return result;
}
示例13: RunTask
private bool RunTask(ITask task)
{
try
{
Console.WriteLine("Starting task: " + task.Name);
Lock(task);
task.Execute(_pipeCommunicator.CancelToken);
UnLock(task);
return true;
}
catch (Exception ex)
{
UnLock(task, ex);
}
return false;
}
示例14: ExecuteInstantiatedTask
/// <summary>
/// Execute a task object for a given bucket.
/// </summary>
/// <param name="engineProxy"></param>
/// <param name="bucket"></param>
/// <param name="howToExecuteTask"></param>
/// <param name="task"></param>
/// <param name="taskResult">Whether the task returned true from Execute</param>
/// <returns>true if task executed successfully (possibly failed but continueOnError=true)</returns>
private bool ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, out bool taskResult)
{
UpdateContinueOnError(bucket, engineProxy);
taskResult = false;
bool taskExecutedSuccessfully = true;
if (!InitializeTask(task, bucket, engineProxy))
{
// The task cannot be initialized.
ProjectErrorUtilities.VerifyThrowInvalidProject(false, taskNode, "TaskParametersError", TaskName, String.Empty);
}
else
{
bool taskReturned = false;
try
{
taskResult = task.Execute();
taskReturned = true;
}
// if a logger has failed, abort immediately
catch (LoggerException)
{
// Polite logger failure
throw;
}
catch (InternalLoggerException)
{
// Logger threw arbitrary exception
throw;
}
// handle any exception thrown by the task during execution
// NOTE: We catch ALL exceptions here, to attempt to completely isolate the Engine
// from failures in the task. Probably we should try to avoid catching truly fatal exceptions,
// e.g., StackOverflowException
catch (Exception e)
{
if (continueOnError)
{
loggingServices.LogTaskWarningFromException(buildEventContext, e,
// Don't try and log the line/column number for this error if
// ContinueOnError=true, because it's too expensive to do so,
// and this error may be fairly common and expected.
new BuildEventFileInfo(projectFileOfTaskNode), TaskName);
// Log a message explaining why we converted the previous error into a warning.
loggingServices.LogComment(buildEventContext, MessageImportance.Normal, "ErrorConvertedIntoWarning");
}
else
{
loggingServices.LogFatalTaskError(buildEventContext, e,
CreateBuildEventFileInfoForTask(),
TaskName);
}
}
// If the task returned attempt to gather its outputs. If gathering outputs fails set the taskResults
// to false
if (taskReturned)
{
taskResult = GatherTaskOutputs(howToExecuteTask, task, bucket) && taskResult;
}
// If the taskResults are false look at ContinueOnError. If ContinueOnError=false (default)
// mark the taskExecutedSuccessfully=false. Otherwise let the task succeed but log a normal
// pri message that says this task is continuing because ContinueOnError=true
if (!taskResult)
{
if (!continueOnError)
{
taskExecutedSuccessfully = false;
}
else
{
loggingServices.LogComment(buildEventContext, MessageImportance.Normal,
"TaskContinuedDueToContinueOnError",
"ContinueOnError", TaskName, "true");
}
}
}
return taskExecutedSuccessfully;
}