-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