Articles → .NET → Multithreading And Threadpool Basic Example

Multithreading And Threadpool Basic Example











  1. Create a separate thread
  2. Do some process using the thread.
  3. Destroy the thread.












  4. public void CreateFiles(object o) {
      for (int i = 1; i < 1000; i++) {
        // Create an XMLDocument instance        
        XmlDocument doc = new System.Xml.XmlDocument();
        // Load the Xml String into XmlDocument        
        doc.LoadXml("<Root></Root>");
        // Save the document        
        doc.Save("C:\\karan\\" + i.ToString() + ".xml");
      }
      MessageBox.Show("done");
    }


  5. Now on an event say button click call the function.
  6. bool status = ThreadPool.QueueUserWorkItem(new WaitCallback(CreateFiles));
    MessageBox.Show("karan");







What Is The Difference Between Process And Thread?


  1. A process contains multiple threads
  2. A processor executes threads not processes
  3. Different processes can't work under the same memory location. But the threads can work under the same memory area
  4. A process can be executed as a single entity whereas thread cannot be executed as a single entity



Posted By  -  Karan Gupta
 
Posted On  -  Monday, August 30, 2010

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250