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


C# Task.Every方法代码示例

本文整理汇总了C#中System.Threading.Tasks.Task.Every方法的典型用法代码示例。如果您正苦于以下问题:C# Task.Every方法的具体用法?C# Task.Every怎么用?C# Task.Every使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Tasks.Task的用法示例。


在下文中一共展示了Task.Every方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TaskFromPromiseWithResultIndexWorksWhenPromiseCompletes

		public void TaskFromPromiseWithResultIndexWorksWhenPromiseCompletes() {
			var promise = CreatePromise();
			var tasks = new Task<int>[] {
				Task.FromPromise<int>(promise, 0),
				Task.FromPromise<int>(promise, 1),
				Task.FromPromise<int>(promise, 2),
				Task.FromPromise<int>(promise, -3),
				Task.FromPromise<int>(promise, -2),
				Task.FromPromise<int>(promise, -1),
			};
			var continuationsRun = new bool[6];
			Assert.IsTrue(tasks.Every(t => t.Status == TaskStatus.Running), "Tasks should be running after being created");
			tasks.ForEach((x, i, _) => x.ContinueWith(t => {
				Assert.IsTrue(t == x, "ContinueWith parameter should be correct");
				continuationsRun[i] = true;
			}));

			Window.SetTimeout(() => {
				Assert.IsFalse(continuationsRun.Some(x => x), "Continuations should not be run too early.");
				Assert.IsTrue(tasks.Every(t => t.Status == TaskStatus.Running), "Tasks should be running before promise is completed.");
				promise.Resolve(10, 42, 38);
			}, 100);

			Window.SetTimeout(() => {
				Assert.IsTrue(tasks.Every(t => t.Status == TaskStatus.RanToCompletion), "Task should be completed after promise");
				Assert.IsTrue(continuationsRun.Every(x => x), "Continuations should have been run after promise was completed.");
				Assert.AreEqual(tasks[0].Result, 10, "Task 0 result should be correct");
				Assert.AreEqual(tasks[1].Result, 42, "Task 1 result should be correct");
				Assert.AreEqual(tasks[2].Result, 38, "Task 2 result should be correct");
				Assert.AreEqual(tasks[3].Result, 10, "Task 3 result should be correct");
				Assert.AreEqual(tasks[4].Result, 42, "Task 4 result should be correct");
				Assert.AreEqual(tasks[5].Result, 38, "Task 5 result should be correct");
				QUnit.Start();
			}, 200);
		}
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:35,代码来源:PromiseTests.cs


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