What is a process ?
When a program starts to run , It's a process , Processes include memory and system resources used by running programs and programs .
And a process is composed of multiple threads .

What is thread ?
A thread is an execution flow in a program , Each thread has its own special register ( Stack pointer 、 Program counter, etc ), But the code area is shared , That is, different threads can perform the same function .

What is multithreading ?
Multithreading refers to the program contains multiple execution flows , That is, you can run multiple different threads to perform different tasks in one program at the same time , That is to say, a single program is allowed to create multiple threads executing in parallel to complete their own tasks .

Benefits of multithreading :
Can improve CPU Utilization ratio . In multithreaded programs , When a thread has to wait ,CPU You can run other threads instead of waiting , This greatly improves the efficiency of the program .

Disadvantages of multithreading :
Threads are also programs , So threads need to take up memory , More threads occupy more memory ; 
Multithreading needs coordination and management , So we need to CPU Time tracking thread ; 
Access to shared resources between threads will affect each other , We must solve the problem of competing for shared resources ;
Too many threads lead to too complex control , In the end, it may cause a lot of problems Bug;

The next step is to C# The multithreading mechanism in programming is discussed . In order to avoid creating GUI Those tedious steps , Closer to the essence of threads , All the next programs are console programs , The last part of the program Console.ReadLine() It's to stop the program , In order to see the output of the execution process .

When any program is executed , At least one main thread .

An intuitive thread example :

//SystemThread.cs
using System;
using System.Threading;

namespace ThreadTest
{
class RunIt
{
[STAThread]
static void Main(string[] args)
{
Thread.CurrentThread.Name="System Thread";// Name the current thread "System Thread"
            Console.WriteLine(Thread.CurrentThread.Name+"'Status:"+Thread.CurrentThread.ThreadState);
Console.ReadLine();
}
}
}

Output is as follows : 
System Thread's Status:Running

ad locum , We go through Thread Static properties of class CurrentThread Gets the thread currently executing , For its Name Attribute assignment “System Thread”, Finally, it outputs its current state (ThreadState).

Static properties , This is the property that all objects of this class share , No matter how many instances of this class you create , But there is only one static property of the class in memory . It's easy to understand CurrentThread Why is it static —— Although there are multiple threads at the same time , But at some point ,CPU Only one of them can be executed .

At the head of the program , We used the following namespace :
     using System;
     using System.Threading; 
 
stay .net framework class library in , All classes related to the application of multithreading mechanism are placed in System.Threading In namespace . If you want to use multithreading in your application , You have to include this class .

We offer through it Thread Class to create and control threads ,ThreadPool Class is used to manage thread pools and so on .
( In addition, it also solves the problem of thread execution arrangement , Deadlock , The mechanism of practical problems such as inter thread communication .)

Thread Class has several crucial methods , Described below :
Start(): Start thread ;
Sleep(int): Static methods , Pauses the number of milliseconds specified by the current thread ; 
Abort(): This method is usually used to terminate a thread ;
Suspend(): This method does not terminate an unfinished thread , It just hangs the thread , It can be recovered later ; 
Resume(): Recovery by Suspend() Method to suspend the execution of the thread ;

C# Multithreaded Learning Series :

C# Multithreaded learning ( Two ) How to manipulate a thread
http://www.cnblogs.com/xugang/archive/2008/04/06/1138841.html

C# Multithreaded learning ( 3、 ... and ) producers and consumers
http://www.cnblogs.com/xugang/archive/2008/03/23/1118594.html

C# Multithreaded learning ( Four ) Automatic management of multithreading ( Thread pool )
http://www.cnblogs.com/xugang/archive/2008/03/23/1118584.html

C# Multithreaded learning ( 5、 ... and ) Automatic management of multithreading ( Timer )
http://www.cnblogs.com/xugang/archive/2008/03/23/1118537.html

C# Multithreaded learning ( 6、 ... and ) Mutexes
http://www.cnblogs.com/xugang/archive/2008/03/23/1118530.html

Related articles :
DotNet Thread problem solving

Visual C# Using threads in

C# Summary of thread resource synchronization mode

C# Thread lecture series (1):BeginInvoke and EndInvoke Method

author : XuGang    Net name : Steel steel
Source : http://xugang.cnblogs.com
Statement :  The copyright of this article belongs to the author and blog Park . This statement must be retained when reprinting , And give the original connection address in the obvious position of the article page !

C# Multithreaded learning ( One ) Multithreading related concepts of more related articles

  1. C# Multithreaded learning ( One ) Multithreading related concepts ( turn )

    What is a process ? When a program starts to run , It's a process , Processes include memory and system resources used by running programs and programs . And a process is composed of multiple threads . What is thread ? A thread is an execution flow in a program , Each thread has its own special thread ...

  2. [ Reprint ]C# Multithreaded learning ( One ) Multithreading related concepts

    Original address :http://www.cnblogs.com/xugang/archive/2008/04/06/1138856.html What is a process ? When a program starts to run , It's a process , Processes include running ...

  3. C# Multithreaded learning ( Four ) Automatic management of multithreading ( Thread pool )

    In a multithreaded program , There are two things that happen very often : A situation :    In the application , Threads spend most of their time waiting , Waiting for something to happen , The response can then be given                    This is commonly used ThreadPo ...

  4. C++ Concurrent and multithreaded learning notes -- Multithreading data sharing problem

    Creating and waiting for multiple threads Analysis of data and sharing problems Read only data Read and write Other cases Shared data protection case code Creating and waiting for multiple threads Server side background development requires multiple threads to perform different tasks . Different threads perform different tasks , And return the execution result . ...

  5. C# Multithreaded learning ( 5、 ... and ) Automatic management of multithreading ( Timer )

    Timer class : Set a timer , Execute user specified functions regularly .                When the timer starts , The system will automatically create a new thread , Execute user specified functions . Initialize a Timer object :  Timer timer ...

  6. 【 turn 】C# Multithreaded learning

    C# Multithreaded learning ( One ) Multithreading related concepts What is a process ? When a program starts to run , It's a process , Processes include memory and system resources used by running programs and programs . And a process is composed of multiple threads . What is thread ? Threads are programs ...

  7. C# Multithreading learning summary

    C# Multithreading learning summary C# Multithreaded learning ( One ) Multithreading related concepts What is a process ? When a program starts to run , It's a process , Processes include memory and system resources used by running programs and programs . And a process is composed of multiple threads . ...

  8. C# Multithreaded learning ( 6、 ... and ) Mutexes

    How to control the connection between multiple threads , There is no conflict or repetition , This requires mutex objects , namely :System.Threading In namespace Mutex class . We can Mutex Think of it as a taxi , Passengers think of it as threads . Passengers first ...

  9. Java Multithreaded learning ( One )Java Getting started with multithreading

    Please note the address for reprint :https://blog.csdn.net/qq_34337272/article/details/79640870 Series article portal : Java Multithreaded learning ( One )Java Getting started with multithreading Ja ...

Random recommendation

  1. POJ 1815 Friendship

    Friendship Time Limit: 2000MS   Memory Limit: 20000K Total Submissions: 10626   Accepted: 2949 Descr ...

  2. ios in scrollview Nested above tableView, Slide left and right to refresh the data many times

    Be careful scrollView Don't refresh data while sliding left and right , Request all data at once when you first come in Red envelope records and housing information can slide left and right and click ,tableView It can slide up and down , The personal information in the picture is refreshed only once . The interface layout is as follows

  3. Android 2016 New technology

    Android 2016 New technology Copyright notice : This article is an original blog article , No reprint without the permission of the blogger . 2016 You need to understand Android There are the following emerging technologies and frameworks , Some may be immature , But you should get to know , Maybe it's the future direction . ...

  4. TortoiseSVN, Rule out ways that you don't want to submit documents ( turn )

    from :tortoisesvnsubversionfilebuilddialoglist Here is the English help : utilize TortoiseSVN A list of changes   Function can be realized , In the new version TortoiseSVN Specially preset ...

  5. NodeJS Learning notes ( One )—— Build development framework Express, Realization Web Website login verification

    JS It's script language , Scripting languages all need a parser to run . For writing in HTML On the page JS, Browsers act as parsers . And for those that need to run independently JS,NodeJS It's a parser . Every parser is a running environment , Not only is it allowed J ...

  6. 【Java】【Flume】Flume-NG The startup process of source code analysis ( two )

    This section analyzes the parsing of configuration files , namely PollingPropertiesFileConfigurationProvider.FileWatcherRunnable.run Medium eventBus.post(getCo ...

  7. web Front end free resource set

    web Front end free resource set  https://github.com/vhf/free-programming-books/blob/master/free-programming-books-zh.md

  8. ERROR 1045 (28000): Access denied for user 'xxx'@'localhost' (using password: YES)【 Wonderful bug】

    #  Bug describe Today is the weekend , Learn new technology at home , Although the task assigned by the company has not been completed ( Funny ) I created a mysql database , use root Users create a new user , After all, the project uses root It's very dangerous , Especially for me ...

  9. jq Animation slide left and right

    <!DOCTYPE html> <html> <head> <title>jquery Animation slide </title> <style type ...

  10. Linux Kernel space memory request function kmalloc、kzalloc、vmalloc

    We all know that the function used to dynamically request memory in user space is malloc(), The use of this function on various operating systems is consistent , The corresponding user space memory release function is free(). Be careful : Dynamic application of memory must be released after use , Otherwise, it will cause internal ...