Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public class Program
  2. {
  3. static public void Main()
  4. {
  5. var library = new Library();
  6. library.Callback = GetMoreData;
  7. var task = Task.Run( () => library.Foo() );
  8. Console.WriteLine("Other thread is running.");
  9. task.Wait();
  10. }
  11.  
  12. static string GetMoreData()
  13. {
  14. return "More data";
  15. }
  16. }
  17.  
  18.  
  19.  
  20. class Library
  21. {
  22. public Func<string> Callback { get; set; }
  23.  
  24. public async Task Foo()
  25. {
  26. for (int i=0; i<10; i++)
  27. {
  28. var moreData = Callback();
  29. Console.WriteLine("Library received this data: {0}", moreData);
  30. await Task.Delay(500);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement