Newbie question for you. I have the following code. I get an error because a object has to be passed to ClientRequest. But am unsure how pass the stream as a object.
TcpClient _client = _listener.AcceptTcpClient();
NetworkStream _开发者_Python百科clientStream = _client.GetStream();
ThreadPool.QueueUserWorkItem(ClientRequest, _clientStream);
Thanks
There's nothing wrong with that code as long as ClientRequest is declared like so:
public void ClientRequest(Object state) {
...
}
The problem is probably not that you can't pass the stream as an object -- Everything in .net is an object, so casting to object (which is a "widening" conversion, and thus doesn't need to be specified) shouldn't be an issue.
My guess is your ClientRequest is expecting to be passed a NetworkStream or something, which it's not going to get -- it's going to get an object, which you'll then need to cast to a NetworkStream in order to use it properly.
精彩评论