J
jesbin
Hi,
I'm using a async callback mechanism to receive data from
the socket. Once the data is received, I parse the data
and if certain information is received I open a new form.
Everything goes fine until the form is opened. The opened
form seems to freeze and does not refresh (no errors are
generated). However, If I output the received data to the
console it seems to be receiving data. The problem is
only with the UI.
Part of the code is included below (pls let me know if
you need the entire source code).
private void Receive()
{
try
{
if ( callbackProc == null )
callbackProc = new AsyncCallback(ReceiveCallback);
StateObject state=new StateObject();
state.workSocket = s;
s.BeginReceive(state.buffer, 0,
StateObject.BufferSize,
SocketFlags.None, callbackProc, state);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ReceiveCallback (IAsyncResult ar)
{
try
{
StateObject state = (StateObject) ar.AsyncState;
int bytesRead = state.workSocket.EndReceive(ar);
string szData =
System.Text.Encoding.Unicode.GetString
(state.buffer, 0, bytesRead);
frmNew n = new frmNew();
n.show();
Receive();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
I'm using a async callback mechanism to receive data from
the socket. Once the data is received, I parse the data
and if certain information is received I open a new form.
Everything goes fine until the form is opened. The opened
form seems to freeze and does not refresh (no errors are
generated). However, If I output the received data to the
console it seems to be receiving data. The problem is
only with the UI.
Part of the code is included below (pls let me know if
you need the entire source code).
private void Receive()
{
try
{
if ( callbackProc == null )
callbackProc = new AsyncCallback(ReceiveCallback);
StateObject state=new StateObject();
state.workSocket = s;
s.BeginReceive(state.buffer, 0,
StateObject.BufferSize,
SocketFlags.None, callbackProc, state);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ReceiveCallback (IAsyncResult ar)
{
try
{
StateObject state = (StateObject) ar.AsyncState;
int bytesRead = state.workSocket.EndReceive(ar);
string szData =
System.Text.Encoding.Unicode.GetString
(state.buffer, 0, bytesRead);
frmNew n = new frmNew();
n.show();
Receive();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}