[問題] 在debug時跑起來沒問題,直接跑*.exe就出問題

看板C_Sharp (C#)作者 (just do it)時間18年前 (2007/06/11 20:48), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
我寫一個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
文章代碼(AID): #16RKIFri (C_Sharp)
文章代碼(AID): #16RKIFri (C_Sharp)