0

我必须创建新线程并将参数发送到线程函数,但无法使其工作。我根据这个参考工作:http: //msdn.microsoft.com/en-us/library/system.threading.parameterizedthreadstart.aspx

这是线程创建(评论中有错误):

System::Threading::Thread^ T = gcnew System::Threading::Thread(gcnew System::Threading::ParameterizedThreadStart(this, &Server::ClientHandler)); // ERROR: 'void Server::ClientHandler(System::Object ^,System::Object ^)' : the specified function does not match the delegate type 'void (System::Object ^)'
T->Start(ClientSocket); // ERROR: 'System::Threading::Thread::Start' : no overloaded function takes 2 arguments

这是ClientHandler声明:

void Server::ClientHandler(Object^ data, Object^ data1);

我只用一个参数尝试过,我只有第二个错误。

PS,在ClientHandler函数中我必须将Object^参数转换为SOCKET*and SOCKADDR_IN*,怎么做?

我的尝试:

SOCKET* _Sock = (SOCKET*)data;
SOCKADDR_IN* _ADDR = (SOCKADDR_IN*)data1;

我正在使用视觉工作室 2012。

4

1 回答 1

2

很确定 for 的声明Server::ClientHandler是不正确的。

应该:

void Server::ClientHandler(Object^ data)
{
    //Do stuff with data here..
}

System::Threading::Thread^ T = gcnew System::Threading::Thread(gcnew System::Threading::ParameterizedThreadStart(this, &Server::ClientHandler));
T->Start("Pass Your Data Here");
于 2013-09-16T20:55:28.393 回答