Guest User

Untitled

a guest
Jul 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10.     class ServiceClient
  11.     {
  12.         public ServiceClient(string address, int port) { }
  13.         public IEnumerable<string>ProcessRequests( IEnumerable<string> next )
  14.         {
  15.             foreach (var req in next)
  16.             {
  17.                 yield return req + " Done";
  18.             }
  19.         }
  20.     }
  21.     class Program
  22.     {
  23.         private static System.Object lockThis = new System.Object();
  24.         static IEnumerable<string> GenerateRequest()
  25.         {
  26.             for (int i = 0; i < 20; i++)
  27.             {
  28.                 yield return string.Format("get_user({0})", i);
  29.             }
  30.         }
  31.         static void Main(string[] args)
  32.         {
  33.             var client = new ServiceClient("", 0);
  34.             Parallel.ForEach( client.ProcessRequests( GenerateRequest() ),
  35.                 (x) => System.Console.WriteLine(x)
  36.                 );
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment