Something really strange:
I get an ObjectDisposedException at this line:
But:
(Note de MessageBox in WaitForData())
Works perfect.
Whats wrong?
C#:
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:
C#:
int bufferOffset = this.Socket.EndReceive(result);
But:
C#:
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;
}
}
Works perfect.
Whats wrong?