Guest User

Untitled

a guest
Aug 20th, 2019
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ChannelFactory<IService1> factory = new ChannelFactory<IService1>("BasicHttpBinding_IService1");
  2.  
  3. Task<string> t1 = Task<string>.Factory.StartNew(() => { return factory.CreateChannel().GetData(2); });
  4. Task<string> t2 = Task<string>.Factory.StartNew(() => { return factory.CreateChannel().GetData(5); });
  5.  
  6. Task.Factory.ContinueWhenAll(new[] { t1, t2 }, t =>
  7. {
  8. foreach (var task in t)
  9. {
  10. //get result here
  11. }
  12. });
  13.  
  14. [ServiceContract(Namespace = "X", Name = "TheContract")]//Server side contract
  15. public interface IService1
  16. {
  17. [OperationContract]
  18. string GetData(int value);
  19. }
  20.  
  21. [ServiceContract(Namespace = "X", Name = "TheContract")]//client side contract
  22. public interface IService1Async
  23. {
  24. [OperationContract]
  25. string GetData(int value);
  26.  
  27. [OperationContract]
  28. Task<string> GetDataAsync(int value);
  29. }
  30.  
  31. ChannelFactory<IService1Async> factory = new ChannelFactory<IService1Async>("BasicHttpBinding_IService2");
  32.  
  33. var t1 = factory.CreateChannel().GetDataAsync(2);
  34. var t2 = factory.CreateChannel().GetDataAsync(5);
  35.  
  36. Task.Factory.ContinueWhenAll(new[] { t1, t2 }, (Task<string>[] t) =>
  37. {
  38. foreach (var task in t)
  39. {
  40. //get result here
  41. }
  42. });
RAW Paste Data