Advertisement
vakho

Aslan ADO.NET Asynchronous Processing

Nov 14th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1.     using System;
  2.     using System.Collections.Generic;
  3.     using System.Linq;
  4.     using System.Text;
  5.     using System.Threading.Tasks;
  6.     using System.Data.SqlClient;
  7.      
  8.     namespace Asynchronous_Console_App
  9.     {
  10.         class Program
  11.         {
  12.          
  13.      
  14.             static void Main(string[] args)
  15.             {
  16.      
  17.              SqlDataAdapter dataAdapter = new SqlDataAdapter();
  18.              SqlConnection con = new SqlConnection("Server=CHALAURI; Database=Students; Integrated Security=true; Asynchronous Processing = true;");
  19.      
  20.                 string command = "UPDATE Students SET NUMBER = NUMBER+1; " + "WAITFOR DELAY '0:0:10'" + " UPDATE Students SET NUMBER = NUMBER+1";
  21.          
  22.      
  23.                 SqlCommand update = new SqlCommand(command, con);
  24.      
  25.                 con.Open();
  26.      
  27.                 IAsyncResult result = update.BeginExecuteNonQuery();
  28.      
  29.                  while (!result.IsCompleted)
  30.                    {
  31.                        Console.WriteLine(DateTime.Now.ToLongTimeString());
  32.                        System.Threading.Thread.Sleep(2000);
  33.                     }
  34.      
  35.      
  36.                 update.EndExecuteNonQuery(result);
  37.                 con.Close();
  38.             }
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement