Articles → .NET → Multithreading and Threadpool Basic Example

Multithreading and Threadpool Basic Example











•   Create a separate thread

•   Do some process using the thread.

•   Destroy the thread.













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");    
}


•   Now on an event say button click call the function.

bool status = ThreadPool.QueueUserWorkItem(new WaitCallback(CreateFiles));
MessageBox.Show("karan");







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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250