[backcolor=rgb(244, 244, 244) !important]1
2
[backcolor=rgb(244, 244, 244) !important]3
4
[backcolor=rgb(244, 244, 244) !important]5
6
[backcolor=rgb(244, 244, 244) !important]7
8
[backcolor=rgb(244, 244, 244) !important]9
10
[backcolor=rgb(244, 244, 244) !important]11
12
[backcolor=rgb(244, 244, 244) !important]13
14
[backcolor=rgb(244, 244, 244) !important]15
16
[backcolor=rgb(244, 244, 244) !important]17
18
[backcolor=rgb(244, 244, 244) !important]19
20
[backcolor=rgb(244, 244, 244) !important]21
22
[backcolor=rgb(244, 244, 244) !important]23
24
[backcolor=rgb(244, 244, 244) !important]25
26
[backcolor=rgb(244, 244, 244) !important]27
28
[backcolor=rgb(244, 244, 244) !important]29
30
[backcolor=rgb(244, 244, 244) !important]31
32
[backcolor=rgb(244, 244, 244) !important]33
34
[backcolor=rgb(244, 244, 244) !important]35
36
[backcolor=rgb(244, 244, 244) !important]37
38
[backcolor=rgb(244, 244, 244) !important]39
40
[backcolor=rgb(244, 244, 244) !important]41
42
[backcolor=rgb(244, 244, 244) !important]43
44
[backcolor=rgb(244, 244, 244) !important]45
46
[backcolor=rgb(244, 244, 244) !important]47
48
[backcolor=rgb(244, 244, 244) !important]49
| [backcolor=rgb(244, 244, 244) !important]using System;
using System.Threading;
namespace StudyThread
[backcolor=rgb(244, 244, 244) !important]{
class Program
[backcolor=rgb(244, 244, 244) !important] {
static void Main(string[] args)
[backcolor=rgb(244, 244, 244) !important] {
OneThread();
[backcolor=rgb(244, 244, 244) !important] }
[backcolor=rgb(244, 244, 244) !important] static void OneThread()
{
[backcolor=rgb(244, 244, 244) !important] Thread threadA = new Thread(ThreadMethod);
threadA.IsBackground = true; //设置当前子线程为后台线程,为后台线程意味着,主线程关闭后,其他子线程都同时关闭
[backcolor=rgb(244, 244, 244) !important] threadA.Start();
[backcolor=rgb(244, 244, 244) !important] object ThreadParameter = "P";
Thread threadB = new Thread(new ParameterizedThreadStart(ThreadMethodParameter));
[backcolor=rgb(244, 244, 244) !important] threadB.IsBackground = true;
threadB.Start(ThreadParameter);
Console.WriteLine("Main Write:M");
[backcolor=rgb(244, 244, 244) !important] Console.ReadLine();
}
static void ThreadMethod()
[backcolor=rgb(244, 244, 244) !important] {
for (int i = 0; i < 10; i++)
[backcolor=rgb(244, 244, 244) !important] {
Console.WriteLine("A");
[backcolor=rgb(244, 244, 244) !important] }
}
/// <summary>
[backcolor=rgb(244, 244, 244) !important] /// 带参数线程
/// </summary>
[backcolor=rgb(244, 244, 244) !important] /// <param name="Parameter">只能定义一个object参数,因为委托ParameterizedThreadStart为单参数object类型</param>
static void ThreadMethodParameter(object Parameter)
[backcolor=rgb(244, 244, 244) !important] {
for (int j = 0; j < 10; j++)
[backcolor=rgb(244, 244, 244) !important] {
Console.WriteLine("B"+Parameter);
[backcolor=rgb(244, 244, 244) !important] }
}
}
[backcolor=rgb(244, 244, 244) !important]}
|