[2.0] Can not open form inside callback method?!
Hello everyone. I am programming a small client/server application and was wondering how I queue a form to open inside an asyncronous callback method and just have it stay open.
The form doesn't load, like it is being accessed millions of times or whatever. I think the main thing is is that I am having problems pausing the asyncronous method while I open the form.
Please help me, this is very frustrating as I have been working on this for about a day now!
Code:
private static void RCallback(IAsyncResult result)
{
try
{
StateObject state = (StateObject)result.AsyncState;
Socket client = state.workSocket;
AutoResetEvent autoReset = new AutoResetEvent(false);
int bytesRead = client.EndReceive(result);
if (bytesRead > 0)
{
state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
client.BeginReceive(state.buffer, 0, state.buffer.Length, SocketFlags.None, new AsyncCallback(RCallback), state);
}
else
{
String content = state.sb.ToString();
if (content.IndexOf("/&END&") > -1)
{
string[] Interpret = content.Split(new char[] { '/' });
if (Interpret[0] == "SuccessfulLogin")
{
MessageBox.Show(Interpret[1].ToString(), "Server Message of the Day!");
autoReset.Reset();
gameForm form = new gameForm();
form.Show();
form.Activate();
}
else if (Interpret[0] == "FailedLogin")
{
MessageBox.Show("This username and password combiniation is invalid!", "Invalid Login ID!");
}
}
}
}
catch (Exception rEX)
{
MessageBox.Show(String.Format("Recieve Failed Because {0}", rEX.Message), "Recieve Data Error!");
}
}