using namespace System;
using namespace System::Threading;
namespace NNNN
{
public ref class TTTT
{
static Thread^ t1;
static Thread^ t2;
void fun()
{
t1 = gcnew Thread(gcnew ParameterizedThreadStart(DoWork1));
t2 = gcnew Thread(gcnew ParameterizedThreadStart(DoWork2));
Tuple<int, char, String^>^ tuple1 = Tuple::Create(1, 'a', "111");
t1->Start(tuple1);
t2->Start(tuple1);
}
}
//传入线程的函数必须是静态的 形参必须是object
//多个参数使用tuple作为整体传入
static void DoWork1(System::Object^ i)
{
Tuple<int, char, String^>^ primes = (Tuple<int, char, String^>^)i;
String^ s = Convert::ToString(primes->Item3);
// do somethings....
}
static void DoWork2(System::Object^ i)
{
//使用join方法可以保证线程2必须在线程1后面执行
t1->Join();
Tuple<int, char, String^>^ primes = (Tuple<int, char, String^>^)i;
String^ s = Convert::ToString(primes->Item3);
// do somethings....
}
}
标签:CLI,Thread,Tuple,System,C++,gcnew,static,primes,多线程
From: https://www.cnblogs.com/sandersshine/p/18504466