using System; using System.Data; using System.Data.SqlClient; using System.Threading.Tasks; namespace NS { class Program { static void Main(string[] args) { // 동시에 100개 쓰레드를 만들어 병렬 실행 // CPU Core 갯수에 따라 자동 병렬 처리 Parallel.For(0, 100, (i) => Run(i)); } static void Run(int i) { var strConn = "Data Source=Test1;Initial Catalog=DB1;Integrated Security=true"; using (var conn = new SqlConnection(strConn)) { conn.Open(); var cmd = new SqlCommand("sp_GetNext", conn); cmd.CommandType = CommandType.StoredProcedure; // Input param SqlParameter pInput = new SqlParameter("@in", SqlDbType.Int); pInput.Direction = ParameterDirection.Input; pInput.Value = 1; cmd.Parameters.Add(pInput); // Output param SqlParameter pOutput = new SqlParameter("@out", SqlDbType.Int); pOutput.Direction = ParameterDirection.Output; cmd.Parameters.Add(pOutput); cmd.ExecuteNonQuery(); Console.WriteLine(pOutput.Value); } } } }