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");
What Is The Difference Between Process And Thread?
- A process contains multiple threads
- A processor executes threads not processes
- Different processes can't work under the same memory location. But the threads can work under the same memory area
- A process can be executed as a single entity whereas thread cannot be executed as a single entity