Help ThreadPools/Threads
-
Im writing an application that will use the HTTPSocket class in SystemNet. I have checked the msdn documentation regarding thread safety which infact is safe to deploy the class in a thread however im unable to reach a code point of execution where data is supposed to be displayed. Better yet let me copy paste some simple code for everyone to see. The results are dubious. class MyThreadPool { private static int i; private string web_response; private string company; private long thread_id; public MyThreadPool() { } public MyThreadPool(string business_string, long id) { this.company = business_string; this.thread_id = id; ThreadPool.QueueUserWorkItem(new WaitCallback(HackCorps), new AutoResetEvent(true)); } public void HackCorps(Object state) { string[] business = null; business = this.company.Split('^'); Stream business_stream = WebRequest.Create(business[0]).GetResponse().GetResponseStream(); StreamReader business_reader = new StreamReader(business_stream); Console.WriteLine(++i); } } and the main int main(){ string line = null; long i = 0; StreamReader read_business = new StreamReader("f://directory.txt"); while ((line = read_business.ReadLine()) != null) { MyThreadPool pool = new MyThreadPool(line, ++i); }return 0;<----Code get here since all thread classes are created although they aren't processed will cause the probram to terminate. Is there some sort of lock to prevent this? } Thanks for your help...