MrLucky Posted December 8, 2006 Posted December 8, 2006 Something really strange: protected void WaitForData() { if(this.SocketCallback == null) { this.SocketCallback = new AsyncCallback(OnDataReceive); } ServerSocket state = new ServerSocket(); state.Socket = this.Socket; this.Socket.BeginReceive(state.buffer1, 0, state.buffer1.Length, SocketFlags.None, this.SocketCallback, state); } public void OnDataReceive(IAsyncResult result) { ServerSocket socket = (ServerSocket) result.AsyncState; int bufferOffset = this.Socket.EndReceive(result); if(bufferOffset > 0 && bufferOffset != socket.buffer1.Length) { byte[] temp = new byte[bufferOffset]; for(int i = 0; i < temp.Length; i++) { temp[i] = socket.buffer1[i]; } this.buffer1 = temp; temp = null; } } I get an ObjectDisposedException at this line: int bufferOffset = this.Socket.EndReceive(result); But: protected void WaitForData() { if(this.SocketCallback == null) { this.SocketCallback = new AsyncCallback(OnDataReceive); } ServerSocket state = new ServerSocket(); state.Socket = this.Socket; this.Socket.BeginReceive(state.buffer1, 0, state.buffer1.Length, SocketFlags.None, this.SocketCallback, state); MessageBox.Show("Foo"); } public void OnDataReceive(IAsyncResult result) { ServerSocket socket = (ServerSocket) result.AsyncState; int bufferOffset = this.Socket.EndReceive(result); if(bufferOffset > 0 && bufferOffset != socket.buffer1.Length) { byte[] temp = new byte[bufferOffset]; for(int i = 0; i < temp.Length; i++) { temp[i] = socket.buffer1[i]; } this.buffer1 = temp; temp = null; } } (Note de MessageBox in WaitForData()) Works perfect. What's wrong? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.