当前位置: 首页>>代码示例>>C#>>正文


C# Task.Unwrap方法代码示例

本文整理汇总了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;
        }
开发者ID:nzaugg,项目名称:ravendb,代码行数:76,代码来源:ExportDatabaseTask.cs

示例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");
        }
开发者ID:jgelinske,项目名称:orleans,代码行数:30,代码来源:OrleansTaskSchedulerAdvancedTests_Set2.cs

示例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
        }
开发者ID:henricj,项目名称:phonesm,代码行数:52,代码来源:SignalTask.cs


注:本文中的Task.Unwrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。