HELP: form freezing on updating UI, invoke needed?
I am working on a c# compact framework app which communicates with a windows app running on a windows xp machine. I have run into a problem and can't see the error.
On logging in on the client app, on a paocket pc, the server sends back data indicating wether the client app logged in correctly or incorectly. On logging in correctly the client app calls a method which updates the UI, hiding the login UI controls such as textboxes, labels and buttons, and showing the next screen controls which consist of 5 textboxes, 4 labels, 4 radiobuttons. On doing this the client app freezes (when run on a windows XP without emulator), if i run it on a PPC emulator it gives tells me "a managed IndexOutOfRange exception occurred at OnDataReceived + 0xf6 ..."
I feel i may need to use Control.Invoke but dont know how to go about this. Below is a segment of my code where the problem lies.
public void OnDataReceived(IAsyncResult asyn)
{
clearMultipleChoiceTextBoxes();
string [] questionParts = new string[7];
for(int i=0; i<7; ++i)
{
questionParts[i] = "";
}
try
{
SocketPacket theSockId = (SocketPacket)asyn.AsyncState ;
int iRx = theSockId.thisSocket.EndReceive (asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
szData = new System.String(chars);
WaitForData();
}
catch (ObjectDisposedException )
{
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
questionParts = szData.Split(',');
MessageBox.Show (questionParts[2].Substring(0,5));
if(questionParts[2].Substring(0,5) == "Hello")
{
// This is where the app hangs, when it calls this method which
// consists only of hiding and showing textboxes, radiobuttons and
// labels
showQuestionControls();
}
MCQuestion.Items.Add(questionParts[2]);
AnswerATB.Items.Add(questionParts[3]);
AnswerBTB.Items.Add(questionParts[4]);
AnswerCTB.Items.Add(questionParts[5]);
AnswerDTB.Items.Add(questionParts[6]);
correctAnswer = questionParts[7];
}
Any help on this matter would be much appreciated, thank you.
|