本文整理汇总了C#中System.Threading.ManualResetEvent.AsTask方法的典型用法代码示例。如果您正苦于以下问题:C# ManualResetEvent.AsTask方法的具体用法?C# ManualResetEvent.AsTask怎么用?C# ManualResetEvent.AsTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.ManualResetEvent
的用法示例。
在下文中一共展示了ManualResetEvent.AsTask方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_OK_No_TimeOut
public void Test_OK_No_TimeOut()
{
_MRE = new ManualResetEvent(false);
Thread nThread = new Thread(() => ThreadReleaser(2000));
nThread.Start();
Task t = _MRE.AsTask();
t.Should().NotBeNull();
t.Wait();
_RunnedOK.Should().BeTrue();
}
示例2: Test_Cancelled_TimeOut
public void Test_Cancelled_TimeOut()
{
_MRE = new ManualResetEvent(false);
Thread nThread = new Thread(() => ThreadReleaser(5000));
nThread.Start();
Task t = _MRE.AsTask(TimeSpan.FromSeconds(1));
t.Should().NotBeNull();
t.ContinueWith(tt => tt.IsCanceled.Should().BeTrue());
_RunnedOK.Should().BeFalse();
}
示例3: SearchAsync
public async Task SearchAsync(CancellationTokenSource cancellationTokenSource)
{
ManualResetEvent waitEvent = new ManualResetEvent(false);
object[] objects = new object[] { checker, proxyProvider };
foreach (object @object in objects)
{
IAsyncInitialization asyncInitialization = @object as IAsyncInitialization;
if (asyncInitialization != null)
asyncInitialization.InitializeAsync(cancellationTokenSource, taskManager, httpDownloaderContainer, this, this, geoIP);
}
IEnumerable<ISearchEngine> searchEngines = searchEngine as IEnumerable<ISearchEngine>;
if (searchEngines == null)
{
await SearchAsyncInternal(searchEngine, cancellationTokenSource);
}
else
{
List<Task> tasks = new List<Task>();
foreach (ISearchEngine engine in searchEngines)
{
tasks.Add(SearchAsyncInternal(engine, cancellationTokenSource));
}
await Task.WhenAll(tasks);
}
taskManager.OnCompleted += () =>
{
waitEvent.Set();
};
await waitEvent.AsTask();
}