public static void SendProc(object temp) { Temp tmp = new Temp(); tmp.Producer = ((Temp)temp).Producer; tmp.ThreadNO = ((Temp)temp).ThreadNO; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); for (int idx = 0; idx < 2000; idx++) { tmp.Producer.SendMessage("Hello world: {"+ tmp.ThreadNO + "}-[" + (idx+1) + "]"); //Thread.Sleep(200); } stopWatch.Stop(); Console.WriteLine("Thread {0}: {1}.", tmp.ThreadNO, stopWatch.Elapsed); Thread.EndThreadAffinity(); }
static void Main(string[] args) { producer.TopicName = "abc-abc"; producer.IsACK = true; int numThreadNum = 5; for (int idx = 0; idx < numThreadNum; idx++) { Temp tmp = new Temp(); tmp.Producer = producer; tmp.ThreadNO = idx + 1; Thread thread = new Thread(new ParameterizedThreadStart(Program.SendProc)); thread.Start(tmp); } Thread.Sleep(5000); Environment.Exit(0); }