//--------------------------------------------------------------------- private void BtnGoThreadTest_Click(object sender, EventArgs e) { LbThreadTime.Visible = false; ThreadTestData[] threads = new ThreadTestData[(Int32)numThreads.Value]; for (Int32 i = 0; i < threads.Length; i++) { threads[i] = new ThreadTestData(); threads[i].TotalTime = 0; threads[i].ThreadId = i + 1; threads[i].MessageCount = (Int32)numThreadMessages.Value; threads[i].RI = RILogManager.Default; threads[i].TheThread = new Thread(ThreadTestThread); threads[i].TheThread.Start(threads[i]); } Int64 totalTime = 0; for (Int32 i = 0; i < threads.Length; i++) { threads[i].TheThread.Join(); totalTime += threads[i].TotalTime; } LbThreadTime.Text = String.Format("{0} msecs", totalTime); LbThreadTime.Visible = true; }
//--------------------------------------------------------------------- private void ThreadTestThread(Object data) { ThreadTestData tData = (ThreadTestData)data; Stopwatch sw = new Stopwatch(); sw.Start(); using (tData.RI.TraceMethod("Thread: {0}", tData.ThreadId)) { for (Int32 i = 0; i < tData.MessageCount; i++) { tData.RI.SendMsg("Sent by thread {0}: {1}", tData.ThreadId, i + 1); } } sw.Stop(); tData.TotalTime = sw.ElapsedMilliseconds; }