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


C# JobHost.DoWork方法代码示例

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


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

示例1: ThrowsArgumentNullExceptionIfWorkIsNull

            public void ThrowsArgumentNullExceptionIfWorkIsNull()
            {
                var host = new JobHost();

                var exception = Assert.Throws<ArgumentNullException>(() => host.DoWork(null));

                Assert.Equal("work", exception.ParamName);
            }
开发者ID:regisbsb,项目名称:WebBackgrounder,代码行数:8,代码来源:JobHostFacts.cs

示例2: EnsuresNoWorkIsDone

            public void EnsuresNoWorkIsDone()
            {
                var host = new JobHost();
                var task = new Task(() => { throw new InvalidOperationException("Hey, this is supposed to be shut down!"); });

                host.Stop(true);

                host.DoWork(task);
            }
开发者ID:regisbsb,项目名称:WebBackgrounder,代码行数:9,代码来源:JobHostFacts.cs

示例3: DoesNotCallStartIfWorkIsAlreadyScheduledOrCompleted

            public void DoesNotCallStartIfWorkIsAlreadyScheduledOrCompleted()
            {
                var tcs = new TaskCompletionSource<object>();
                tcs.SetResult(null);

                var task = tcs.Task;

                var host = new JobHost();

                Assert.DoesNotThrow(() => host.DoWork(task));
            }
开发者ID:regisbsb,项目名称:WebBackgrounder,代码行数:11,代码来源:JobHostFacts.cs

示例4: WaitsForTaskToComplete

            public void WaitsForTaskToComplete()
            {
                var host = new JobHost();
                var workTask = new Task(() => host.DoWork(new Task(() =>
                {
                    // Was getting inconsistent results with Thread.Sleep(100)
                    for (int i = 0; i < 100; i++)
                    {
                        Thread.Sleep(1);
                    }
                })));
                var beforeStop = DateTime.UtcNow;
                workTask.Start();
                while (workTask.Status != TaskStatus.Running)
                {
                    Thread.Sleep(1);
                }

                host.Stop(false);
                var afterStop = DateTime.UtcNow;

                // If Stop didn't wait, we'd expect after to be less than 100 ms larger than beforeStop
                Assert.True((afterStop - beforeStop).TotalMilliseconds >= 100);
            }
开发者ID:regisbsb,项目名称:WebBackgrounder,代码行数:24,代码来源:JobHostFacts.cs


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