static async Task ImagesGetAsyncMUltiple(DbAgent agent) { if (agent.ConnectionLevel == ConnectionLevel.AllInOne) { await agent.OpenConnectionAsync(); } DataSItem itm = new DataSItem(); itm.Schema = "general"; itm.Name = "Images_Get"; // itm.AddParam(new DataParam("@path", CustomSqlTypes.String)); itm.AddReturnParam(CustomSqlTypes.Int); // itm.FillPRocedureParamsFromSQLAgent(agent); // itm.Params.Add("@path",new DataParam()); for (int i = 0; i < 1000; i++) { ExecAsyncResult res1 = await itm.ExecuteDataReaderByRefAsync <Img>(agent); IBag <Img> images = res1.Object as IBag <Img>; Console.WriteLine("Item Count : " + images.Objects.Count.ToString() + " " + res1.ToString()); } if (agent.ConnectionLevel == ConnectionLevel.AllInOne) { agent.Dispose(); } }
static async void ImagesGet(int count, DbAgent agent) { //Images_NewINstance DataSItem itm = new DataSItem(); itm.Schema = "general"; itm.Name = "Images_Get"; // itm.AddParam(new DataParam("@path", CustomSqlTypes.String)); itm.AddReturnParam(CustomSqlTypes.Int); // itm.FillPRocedureParamsFromSQLAgent(agent); // itm.Params.Add("@path",new DataParam()); Task compleateT = RunLimitedNumberAtATime(10, Enumerable.Range(1, count), async x => Task.Factory.StartNew(async() => { // itm.Params["@path"].Value = Guid.NewGuid().ToString(); ExecAsyncResult res = await itm.ExecuteDataReaderByRefAsync <Img>(agent); IBag <Img> images = res.Object as IBag <Img>; Console.WriteLine("Item Count : " + images.Objects.Count.ToString() + " " + res.ToString()); // Console.WriteLine(string.Format("Starting task {0}", x)); // await Task.Delay(1000); //Thread.Sleep(methodWait); // Console.WriteLine(string.Format("Finishing task {0}", x)); }, TaskCreationOptions.LongRunning)); await compleateT; }
static async void NewImages(int count, DbAgent agent) { //Images_NewINstance DataSItem itm = new DataSItem { // itm.Schema = "general"; Schema = "dbo", Name = "Images_NewINstance" }; itm.AddParam(new DataParam("@path", CustomSqlTypes.String)); itm.AddReturnParam(CustomSqlTypes.Int); // itm.FillPRocedureParamsFromSQLAgent(agent); // itm.Params.Add("@path",new DataParam()); Task compleateT = RunLimitedNumberAtATime(10, Enumerable.Range(1, count), async x => Task.Factory.StartNew(async() => { itm.Params["@path"].Value = Guid.NewGuid().ToString(); ExecAsyncResult res = await itm.ExecuteNonQueryAsync(agent); Console.WriteLine(res.ToString()); // Console.WriteLine(string.Format("Starting task {0}", x)); // await Task.Delay(1000); //Thread.Sleep(methodWait); // Console.WriteLine(string.Format("Finishing task {0}", x)); }, TaskCreationOptions.LongRunning)); await compleateT; }
static async Task NewImagesViaAgent(DbAgent agent) { DataSItem itm = new DataSItem { // itm.Schema = "general"; Schema = "general", Name = "Images_NewINstance" }; itm.AddParam(new DataParam("@path", CustomSqlTypes.String, ParamDirection.Input, Guid.NewGuid().ToString())); itm.AddReturnParam(CustomSqlTypes.Int); // itm.Params["@path"].Value = Guid.NewGuid().ToString(); await agent.OpenConnectionAsync(); ExecAsyncResult res = await itm.ExecuteNonQueryAsync(agent); Console.WriteLine(res.ToString()); itm.Params["@path"].Value = Guid.NewGuid().ToString(); res = await itm.ExecuteNonQueryAsync(agent); Console.WriteLine(res.ToString()); agent.Dispose(); }
static async void ImagesGetAsyncNewTest(DbAgent agent) { if (agent.ConnectionLevel == ConnectionLevel.AllInOne) { await agent.OpenConnectionAsync(); } DataSItem itm = new DataSItem(); itm.Schema = "general"; itm.Name = "Images_Get"; // itm.AddParam(new DataParam("@path", CustomSqlTypes.String)); itm.AddReturnParam(CustomSqlTypes.Int); // itm.FillPRocedureParamsFromSQLAgent(agent); // itm.Params.Add("@path",new DataParam()); List <Task <ExecAsyncResult> > _alltaskst = new List <Task <ExecAsyncResult> >(); for (int i = 0; i < 2; i++) { Task <ExecAsyncResult> t = itm.ExecuteDataReaderByRefAsync <Img>(agent); _alltaskst.Add(t); } while (_alltaskst.Count > 0) { Task <ExecAsyncResult> fintask = await Task.WhenAny(_alltaskst); _alltaskst.Remove(fintask); ExecAsyncResult result = await fintask; IBag <Img> images = result.Object as IBag <Img>; Console.WriteLine("Item Count : " + images.Objects.Count.ToString() + " " + result.ToString()); } // itm.Params["@path"].Value = Guid.NewGuid().ToString(); // Console.WriteLine(string.Format("Starting task {0}", x)); // await Task.Delay(1000); //Thread.Sleep(methodWait); // Console.WriteLine(string.Format("Finishing task {0}", x)); if (agent.ConnectionLevel == ConnectionLevel.AllInOne) { agent.Dispose(); } }
static async Task ReflectionGetAsync(DbAgent agent) { DataSItem itm = new DataSItem(); itm.Schema = "general"; itm.Name = "Images_Get"; // itm.AddParam(new DataParam("@path", CustomSqlTypes.String)); itm.AddReturnParam(CustomSqlTypes.Int); ExecAsyncResult res = await itm.ExecuteDataReaderByRefAsync <Img>(agent); IBag <Img> images = res.Object as IBag <Img>; Console.WriteLine("Item Count : " + images.Objects.Count.ToString() + " " + res.ToString()); }
static void GetImgsync(DbAgent agent) { DataSItem itm = new DataSItem(); itm.Schema = "general"; itm.Name = "Images_Get"; // itm.AddParam(new DataParam("@path", CustomSqlTypes.String)); itm.AddReturnParam(CustomSqlTypes.Int); IBag <Img> images; ExecResult res = itm.ExecuteDataReaderByRef(agent, out images); foreach (Img img in images.Objects) { Console.WriteLine(string.Format("Id : {0} - Path : {1}", img.Id.ToString(), img.Path)); } Console.WriteLine("Item Count : " + images.Objects.Count.ToString() + " " + res.ToString()); }
static async Task ImagesGigImagesGET(int count, DbAgent agent) { DataSItem itm = new DataSItem(); itm.Schema = "general"; itm.Name = "Images_Get"; // itm.AddParam(new DataParam("@path", CustomSqlTypes.String)); itm.AddReturnParam(CustomSqlTypes.Int); // itm.FillPRocedureParamsFromSQLAgent(agent); // itm.Params.Add("@path",new DataParam()); Task compleateT = RunLimitedNumberAtATime(10, Enumerable.Range(1, count), async x => Task.Factory.StartNew(async() => { Console.WriteLine("Start! "); // itm.Params["@path"].Value = Guid.NewGuid().ToString(); ExecAsyncResult res = await itm.ExecuteDataReaderByRefAsync <Img>(agent); IBag <Img> images = res.Object as IBag <Img>; Console.WriteLine("Item Count : " + images.Objects.Count.ToString() + " " + res.ToString()); }, TaskCreationOptions.LongRunning)); await compleateT; }
/* * Start ! * First Path : 558278df-28d0-4bb5-82a1-87d2397569fb * Code : 1 - Execution Time : 224.06 ms * Compleated : 1256 * Second Path : 67e1ed21-3570-4a64-8647-5b030ea03c40 * Code : 1 - Execution Time : 8.617 ms */ static void NewImagesViaAgentSync(DbAgent agent) { DataSItem itm = new DataSItem { // itm.Schema = "general"; Schema = "general", Name = "Images_NewINstance" }; itm.AddParam(new DataParam("@path", CustomSqlTypes.String)); itm.AddReturnParam(CustomSqlTypes.Int); string first = Guid.NewGuid().ToString(); itm.Params["@path"].Value = first; Console.WriteLine("First Path : " + first); // agent.OpenConnection(); //using (agent) //{ // agent.OpenConnection(); agent.OpenConnection(); ExecResult res = itm.ExecuteNonQuery(agent); Console.WriteLine(res.ToString()); first = Guid.NewGuid().ToString(); for (int i = 0; i < 25000; i++) { first = Guid.NewGuid().ToString(); itm.Params["@path"].Value = first; Console.WriteLine($"ThreadId : {Thread.CurrentThread.ManagedThreadId.ToString()} Path i : {i.ToString()} : " + first); res = itm.ExecuteNonQuery(agent); Console.WriteLine(res.ToString()); } bool firstfin = false; Thread t = new Thread(new ThreadStart(delegate { for (int i = 0; i < 25000; i++) { first = Guid.NewGuid().ToString(); itm.Params["@path"].Value = first; Console.WriteLine($"ThreadId : {Thread.CurrentThread.ManagedThreadId.ToString()} Path i : {i.ToString()} : " + first); res = itm.ExecuteNonQuery(agent); Console.WriteLine(res.ToString()); } firstfin = true; })); bool sec = false; Thread t2 = new Thread(new ThreadStart(delegate { for (int i = 0; i < 25000; i++) { first = Guid.NewGuid().ToString(); itm.Params["@path"].Value = first; Console.WriteLine($"ThreadId : {Thread.CurrentThread.ManagedThreadId.ToString()} Path i : {i.ToString()} : " + first); res = itm.ExecuteNonQuery(agent); Console.WriteLine(res.ToString()); } sec = true; })); t.Start(); t2.Start(); while (!(firstfin && sec)) { if (firstfin && sec) { agent.Dispose(); break; } } // agent.CloseConnection(); //itm.Params["@path"].Value = first; //Console.WriteLine("Second Path : " + first); //res = itm.ExecuteNonQuery(agent); //Console.WriteLine(res.ToString()); //} // agent.Dispose(); }