[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple,InstanceContextMode =InstanceContextMode.PerCall)] public class Service1 : IService1 { public List<string> GetData(int value) { List<string> lst = new List<string>(); DateTime dt1 = DateTime.Now; lst.Add("Request :"+value+"---Start Time ----"+dt1.Hour + "_" + dt1.Minute + "_" + dt1.Second + "_" + dt1.Millisecond); Thread.Sleep(2000); dt1 = DateTime.Now; lst.Add("Request :" + value + "---End Time ----"+dt1.Hour + "_" + dt1.Minute + "_" + dt1.Second + "_" + dt1.Millisecond); return lst; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TestWCFConClient { public class MyClient { public async void Do() { List<Task> lsttask = new List<Task>(); DateTime dtf = DateTime.Now; Console.WriteLine("Execution Begin " + dtf.Hour + "_" + dtf.Minute + dtf.Second + "_" + dtf.Millisecond); // ThreadPool.SetMaxThreads(8,8); //ThreadPool.SetMinThreads(8, 8); //int c; //int io; //ThreadPool.GetMaxThreads(out c, out io); List<string[]> lststr = new List<string[]>(); ServiceReference1.Service1Client objClient = new ServiceReference1.Service1Client(); for (int i = 0; i < 2; i++) { try { DateTime dtCurrent = DateTime.Now; int current = i + 1; var objTask = await Task<string[]>.Run(() => { Task<string[]> obj = objClient.GetDataAsync(current); for(int a=0;a<obj.Result.Length;a++ ) { Console.WriteLine(current + obj.Result[a]); } return obj; }); lststr.Add(objTask); // Thread.Sleep(100); } catch (Exception ex) { } } DateTime dte = DateTime.Now; Console.WriteLine("Execution End " + dte.Hour + "_" + dte.Minute + "_" + dte.Second + "_" + dte.Millisecond); } } }
Execution Begin 22_5321_403 1Request :1---Start Time ----22_53_22_703 1Request :1---End Time ----22_53_24_704 2Request :2---Start Time ----22_53_24_798 2Request :2---End Time ----22_53_26_799 Execution End 22_53_26_810
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)