fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. // 非同期で1文字読み取るタスク
  14. Func<ConsoleKeyInfo> readAsync = () => Console.ReadKey(true);
  15. var task = Task.Factory.StartNew(readAsync);
  16.  
  17. while (true)
  18. {
  19. if (task.IsCompleted)
  20. {
  21. Console.WriteLine(task.Result.KeyChar + "が押されました");
  22.  
  23. if (task.Result.KeyChar == 'D')
  24. {
  25. //ここでは文字列を得たい
  26. string input = Console.ReadLine();
  27. Console.WriteLine(input + "が入力されました");
  28.  
  29. if (input == "sss")
  30. {
  31. //sssが入力された時、処理を行う
  32. break;
  33. }
  34. }
  35.  
  36. task = Task.Factory.StartNew(readAsync);
  37. }
  38. }
  39. }
  40. }
  41. }
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(5,24): error CS0234: The type or namespace name `Tasks' does not exist in the namespace `System.Threading'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty