⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadtest.cs

📁 c#多线程源代码
💻 CS
字号:
using System;
using System.Threading;

public class Alpha
{
	public void Beta()
	{
		while (true)
		{
			Console.WriteLine("Alpha.Beta is running in its own thread.");
		}
	}
};
public class Simple
{
	public static int Main()
	{
		Console.WriteLine("Thread Start/Stop/Join Sample");
      
		Alpha oAlpha = new Alpha();
		Thread oThread = new Thread(new ThreadStart(oAlpha.Beta));
		oThread.Start();
		while (!oThread.IsAlive);
		Thread.Sleep(1);
		oThread.Abort();
		oThread.Join();
      
		Console.WriteLine();
		Console.WriteLine("Alpha.Beta has finished");
      
		try 
		{
			Console.WriteLine("Try to restart the Alpha.Beta thread");
			oThread.Start();
		}
		catch (ThreadStateException) 
		{
			Console.Write("ThreadStateException trying to restart Alpha.Beta. ");
			Console.WriteLine("Expected since aborted threads cannot be restarted.");
		}
		return 0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -