-3
A
回答
0
1
线程是一个进程的上下文中执行的指令序列。当程序使用多个执行线程时允许每个线程同时共享CPU,这取决于分配给这些线程的优先级。
你可以参考学习线程
using System;
using System.Threading;
public class Alpha
{
// This method that will be called when the thread is started
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();
// Create the thread object, passing in the Alpha.Beta method
// via a ThreadStart delegate. This does not start the thread.
Thread oThread = new Thread(new ThreadStart(oAlpha.Beta));
// Start the thread
oThread.Start();
// Spin for a while waiting for the started thread to become
// alive:
while (!oThread.IsAlive);
// Put the Main thread to sleep for 1 millisecond to allow oThread
// to do some work:
Thread.Sleep(1);
// Request that oThread be stopped
oThread.Abort();
// Wait until oThread finishes. Join also has overloads
// that take a millisecond interval or a TimeSpan object.
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;
}
}
相关问题
- 1. 多线程概念
- 2. C++程序线程概念
- 3. 线程概念
- 4. 线程概念
- 5. C#多线程概念问题
- 6. 线程和块概念
- 7. Java线程概念
- 8. Wait()和Notify()概念 - Java多线程
- 9. C语言中的线程概念#
- 10. java中多线程的概念
- 11. java多线程的核心概念
- 12. 概念线程问题
- 13. 学习线程概念
- 14. Java线程概念/演示
- 15. JMS多线程概念与MQ
- 16. 何处使用多线程概念
- 17. 对多线程概念有点困惑
- 18. 疑问,在线程的概念
- 19. 线程上的一些概念问题
- 20. 带信号量和伪随机数的概念多线程
- 21. 提升线程概念化/问题
- 22. 在Javascript中实现线程概念?
- 23. 线程是一个Windows概念吗?
- 24. 线程池本地变量概念
- 25. 诺基亚QT SDK线程概念
- 26. C程序概念
- 27. 关于scala语言的多线程概念
- 28. 如何通过多线程的概念下载单个文件
- 29. 了解有关多线程的基本概念
- 30. 多线程COMObject和UI线程(C#)
那是一个非常通用的和基本的问题该代码。在谷歌搜索这个,我相信你会得到很多关于此的信息。 – Luftwaffe
这个问题已经以许多不错的方式回答了很多次,请尽量先试用Google。 –
详细了解它:http://www.albahari.com/threading/ – Tudor