How to write C # multithreading
This article mainly shows you "how to write C# multithreading", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to write C# multithreading" this article.
Writing C# multithreaded applications is very easy, even for beginners who have never written C# multithreaded applications, you can do so by following these simple steps.
Define namespaces
In .NET, multithreading functionality is defined in the System.Threading namespace. Therefore, the System.Threading namespace must be defined before using any thread class. The definition is as follows:
Using System.Threading
Start thread
The Thread class in the System.threading namespace represents a thread object that allows you to create new threads, delete, pause, and resume threads. The following code creates a new thread using the Thread class, and then starts the thread:
Thread = new Thread (new ThreadStart (WriteData)); thread.Start ()
Where WriteData is a function to be executed by this thread, the code is as follows:
Protected void WriteData () {string str; for (int I = 0; I