スキップしてメイン コンテンツに移動

投稿

ラベル(Thread)が付いた投稿を表示しています

ThreadPoolクラスのサンプル

ThreadPoolクラスのサンプルです。C#のソースコードを以下に示します。もっと有益な情報を載せないといけませんね。 using System; using System.Threading; namespace Test { public static class ThreadPoolTest { public static void RunThread() { ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadMethod), "A"); Console.ReadLine(); } private static void ThreadMethod(object state) { for (int i = 0; i < 10; i++) { System.Console.WriteLine(state+":"+i); Thread.Sleep(1000); } } } }

C++.NetでのThreadの実行方法

C++.NetでのThreadの実行方法です。C#でThreadの使い方を知っていれば、理解はしやすいと思います。 using namespace System; using namespace System::Threading; ref class Work { public: static void DoWork() { Console::WriteLine( "Static thread procedure." ); } void DoMoreWork() { Console::WriteLine( "Instance thread procedure."); } }; int main(array ^args) { Work ^w = gcnew Work; ThreadStart ^start = gcnew ThreadStart(w, &Work::DoMoreWork); Thread ^t = gcnew Thread(start); t->Start(); Console::ReadLine(); return 0; }