遇到问题。需要在单独的线程上调用类成员方法 C++/CLI
.h:
ref class BgWorker
{
private:
void MainLoop();
public:
void Start();
};
.cpp:
void BgWorker::MainLoop()
{
while(true)
{
...
}
}
void BgWorker::Start()
{
System::Threading::Thread^ td = gcnew System::Threading::Thread(MainLoop); // v1; didn't working
System::Threading::Thread^ td = gcnew System::Threading::Thread(gcnew System::Threading::ThreadStart(MainLoop)); // v2; didn't
std::thread td(MainLoop); // v3, didn't
}
也通过
System::ComponentModel::DoWorkEventHandler()
试过,很可能我做错了什么
我想使用这个构造函数,但是我无法拉出到 MainLoop 的链接:
public : Thread(System::Threading::ThreadStart^ start)
标准流同样的问题
std::thread
,MainLoop 不是函数引用
我在谷歌上找不到任何关于我的问题的信息。非常感谢您的帮助!
现在VS不骂人有两种选择:
System::Threading::Thread^ td =
gcnew System::Threading::Thread(gcnew System::Threading::ThreadStart(this, &MainLoop));
std::thread td(this);
我认为它应该有效
[编辑]
&MainLoop
- “&”编译器不会跳过
第二个选项导致错误 C2665