Created
February 16, 2015 05:15
-
-
Save ezaurum/746ea24220b52b27b56c to your computer and use it in GitHub Desktop.
await/async run test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication1 | |
{ | |
internal class Program | |
{ | |
private static ConcurrentQueue<int> _a = new ConcurrentQueue<int>(); | |
private static void Main(string[] args) | |
{ | |
Task.WaitAll(GetValue()); | |
Console.ReadLine(); | |
} | |
private static async Task GetValue() | |
{ | |
var stringGetAsync = Test1Async(); | |
var keyDeleteAsync = Test2Async(); | |
if (!await ExecuteAsync()) return; | |
var target = await stringGetAsync; | |
var result = await keyDeleteAsync; | |
Console.WriteLine(target); | |
Console.WriteLine(result); | |
} | |
private static async Task<bool> ExecuteAsync() | |
{ | |
Console.WriteLine("Execute runs." + _a.Count); | |
await Task.Delay(1000); | |
Console.WriteLine("Execute exit."); | |
return true; | |
} | |
private static async Task<bool> Test2Async() | |
{ | |
Console.WriteLine("Test2Async runs." + _a.Count); | |
_a.Enqueue(122); | |
await Task.Delay(10); | |
Console.WriteLine("Test2 exit."); | |
return true; | |
} | |
private static async Task<string> Test1Async() | |
{ | |
Console.WriteLine("Test1Async runs. " + _a.Count); | |
_a.Enqueue(12); | |
await Task.Delay(100); | |
Console.WriteLine("Test1 exit."); | |
return "OK"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment