作者scdog (just do it)
看板C_Sharp
标题[问题] 在debug时跑起来没问题,直接跑*.exe就出问题
时间Mon Jun 11 20:48:14 2007
我写一个socket的程式
直接在debug或release mode下跑都没问题
可是直接跑*.exe就有问题
我的code(client端)如下:
void connect(){
if (this._netStream != null)
this._netStream.Close();
if (this._client != null && _client.Connected)
this._client.Close();
client = new TcpClient(ip, port);
_netStream = _client.GetStream();
Thread t = new Thread(new ThreadStart(this.Echo));
t.Start();
}
void Disconnect(){
if (this._client != null && _client.Connected)
this._client.Close();
// close tcp clint
if (this._netStream != null && _netStream.CanRead)
this._netStream.Close();
}
void echo(){
while (_isAlive)
{
if (_netStream.CanRead)
{
// Reads NetworkStream into a byte buffer.
bytes = null;
bytes = new byte[_client.ReceiveBufferSize];
// Read can return anything from 0 to numBytesToRead.
// This method blocks until at least one byte is read.
try
{
_netStream.Read(bytes, 0, (int)_client.ReceiveBufferSize);
}
catch(System.IO.IOException e){
_isAlive = false;
}
catch (System.ArgumentNullException e)
{
_isAlive = false;
}
catch(System.ObjectDisposedException e){
_isAlive = false;
}
}
}
this.disconnect();
}
这样写的话在debug(release) mode连线都没问题
可是跑*.exe时每间隔一次才连的上
不知道是哪里出问题了。..乾瞎!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.96.194.99