本文整理汇总了C#中Task.Unwrap方法的典型用法代码示例。如果您正苦于以下问题:C# Task.Unwrap方法的具体用法?C# Task.Unwrap怎么用?C# Task.Unwrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task.Unwrap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunImplementation
protected override async Task<DatabaseTaskOutcome> RunImplementation()
{
if (includeDocuments == false && includeAttachements == false && includeIndexes == false && includeTransformers == false)
return DatabaseTaskOutcome.Abandoned;
var saveFile = new SaveFileDialog
{
DefaultExt = ".ravendump",
Filter = "Raven Dumps|*.ravendump;*.raven.dump",
};
var name = ApplicationModel.Database.Value.Name;
var normalizedName = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray());
var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture));
try
{
saveFile.DefaultFileName = defaultFileName;
}
catch { }
if (saveFile.ShowDialog() != true)
{
return DatabaseTaskOutcome.Abandoned;
}
using (var stream = saveFile.OpenFile())
{
ItemType operateOnTypes = 0;
if (includeDocuments)
{
operateOnTypes |= ItemType.Documents;
}
if (includeAttachements)
{
operateOnTypes |= ItemType.Attachments;
}
if (includeIndexes)
{
operateOnTypes |= ItemType.Indexes;
}
if (includeTransformers)
{
operateOnTypes |= ItemType.Transformers;
}
var smuggler = new SmugglerApi(new SmugglerOptions
{
BatchSize = batchSize
},
DatabaseCommands,
message => Report(message));
var forwardtoUiBoundStream = new ForwardtoUIBoundStream(stream);
var taskGeneration = new Task<Task>(() => smuggler.ExportData(forwardtoUiBoundStream, new SmugglerOptions
{
BatchSize = batchSize,
Filters = filterSettings,
TransformScript = transformScript,
ShouldExcludeExpired = shouldExcludeExpired,
OperateOnTypes = operateOnTypes
}, false));
ThreadPool.QueueUserWorkItem(state => taskGeneration.Start());
await taskGeneration.Unwrap();
forwardtoUiBoundStream.Flush();
stream.Flush();
}
return DatabaseTaskOutcome.Succesful;
}
示例2: ActivationSched_NewTask_ContinueWith_Wrapped
public void ActivationSched_NewTask_ContinueWith_Wrapped()
{
TaskScheduler scheduler = masterScheduler.GetWorkItemGroup(context).TaskRunner;
Task<Task> wrapped = new Task<Task>(() =>
{
Console.WriteLine("#0 - new Task - SynchronizationContext.Current={0} TaskScheduler.Current={1}",
SynchronizationContext.Current, TaskScheduler.Current);
Task t0 = new Task(() =>
{
Console.WriteLine("#1 - new Task - SynchronizationContext.Current={0} TaskScheduler.Current={1}",
SynchronizationContext.Current, TaskScheduler.Current);
Assert.AreEqual(scheduler, TaskScheduler.Current, "TaskScheduler.Current #1");
});
Task t1 = t0.ContinueWith(task =>
{
Assert.IsFalse(task.IsFaulted, "Task #1 Faulted=" + task.Exception);
Console.WriteLine("#2 - new Task - SynchronizationContext.Current={0} TaskScheduler.Current={1}",
SynchronizationContext.Current, TaskScheduler.Current);
Assert.AreEqual(scheduler, TaskScheduler.Current, "TaskScheduler.Current #2");
});
t0.Start(scheduler);
return t1;
});
wrapped.Start(scheduler);
bool ok = wrapped.Unwrap().Wait(TimeSpan.FromSeconds(2));
Assert.IsTrue(ok, "Finished OK");
}
示例3: Fire
public void Fire()
{
Task<Task> task;
Task unwrapTask;
lock (_lock)
{
if (_isDisposed)
throw new ObjectDisposedException(GetType().FullName);
if (_isPending || _cancellationTokenSource.IsCancellationRequested)
return;
_isPending = true;
if (null != _task)
return;
task = new Task<Task>(CallHandlerAsync, _cancellationTokenSource.Token, TaskCreationOptions.DenyChildAttach);
_task = unwrapTask = task.Unwrap();
_taskCompletionSource = null;
}
try
{
// We start the outer task *after* leaving the monitor.
if (TaskStatus.Created == task.Status)
task.Start(TaskScheduler.Default);
}
catch (Exception ex)
{
Debug.WriteLine("SignalTask.Fire() task start failed: " + ex.Message);
lock (_lock)
{
if (ReferenceEquals(unwrapTask, _task))
{
_task = null;
_taskCompletionSource = null;
_isPending = false;
}
}
throw;
}
#if DEBUG
if (_isDisposed)
throw new ObjectDisposedException(GetType().FullName);
#endif
}