Ian , Just for information here are the times for a little prog I wrote it is interesting that there is an optomisation in Thread.Start() when starting mutliple threads to the same delgate. The first one takes 40 ms and later ones are very quick (occasionaly the second one takes 10ms) . ThreadPools are quicker when doing different types of work but you dont seem to get this optomisation.
Anyone knows why this occurs is my code wrong ? I do agree threads are a precious resource and should not be wasted but they are not that expensive. Ben Thread class Initialize Time0 ms Thread Start time40ms Thread class Initialize Time0 ms Thread Start time0ms Thread class Initialize Time0 ms Thread Start time0ms Thread class Initialize Time0 ms Thread Start time0ms Thread class Initialize Time0 ms Thread Start time0ms Now using 5 time to do total Thread class Initialize Time0 ms Thread class Initialize Time0 ms Thread class Initialize Time0 ms Thread Start time0ms Thread Start time0ms Thread Start time0ms Thread class Initialize Time10 ms Thread class Initialize Time10 ms Thread Start time10ms Thread Start time10ms Now using ThreadPool Worker Thread Start time10ms Worker Thread Start time100144 Tics Worker Thread Start time20ms Worker Thread Start time200288 Tics Worker Thread Start time20ms Worker Thread Start time200288 Tics Worker Thread Start time20ms Worker Thread Start time200288 Tics Worker Thread Start time20ms Worker Thread Start time200288 Tics Machine is 700 Mhz Duron using System; using System.Threading; namespace ThreadTest { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { static DateTime startTime; static public void Test() { TimeSpan span = DateTime.Now- startTime; Console.WriteLine("Thread Start time" + span.Milliseconds.ToString() + "ms"); } public static void ThreadTest(Object O) { TimeSpan span = DateTime.Now- startTime; Console.WriteLine("Worker Thread Start time" + span.Milliseconds.ToString() + "ms"); Console.WriteLine("Worker Thread Start time" + (span.Ticks).ToString() + " Tics"); } /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { Thread testThread; ThreadStart start = new ThreadStart(Class1.Test); for ( int i = 0 ; i < 5 ; i ++) { startTime = DateTime.Now; testThread = new Thread(start); TimeSpan span = DateTime.Now- startTime; Console.WriteLine("Thread class Initialize Time" + span.Milliseconds.ToString() + " ms"); testThread.Start(); Thread.Sleep(1000); } Thread.Sleep(1000); startTime = DateTime.Now; // ThreadPool threadPool = new ThreadPool(); Console.WriteLine("Now using 5 time to do total"); for ( int i = 0 ; i < 5 ; i ++) { testThread = new Thread(start); TimeSpan span = DateTime.Now- startTime; Console.WriteLine("Thread class Initialize Time" + span.Milliseconds.ToString() + " ms"); testThread.Start(); } Thread.Sleep(1000); startTime = DateTime.Now; // ThreadPool threadPool = new ThreadPool(); Console.WriteLine("Now using ThreadPool"); for ( int i = 0 ; i < 5 ; i ++) { ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadTest)); } String key = Console.ReadLine(); } } } -----Original Message----- From: Moderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED]]On Behalf Of Ben Kloosterman Sent: Tuesday, 11 June 2002 6:12 PM To: [EMAIL PROTECTED] Subject: Re: [ADVANCED-DOTNET] Threading is blocking itself or ? Ian , I Agree on most of your points except this one . >> In this case I may be wrong as the initialization cost of your class may >> be quite high . It may be more efficient to intialize it once and send the >> 50 messages in a loop. > >I suspect the class initialization cost will be low compared to the cost of > creating a thread. His class intialization is doing a network login - the cost of creating a thread is no where near that high - some code Ive got creates a thread and gets a DataSet from a middleTier and takes about 50ms. Ben You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.