I have got a Client/Server Application that using Asynchronous Socket.My problem is i cant start timer control on Client Side from Server side.I have got a method for sending data to client from server side and client got a method for handle this data and starts the timer.There is no problem at getting data and process it.But timer control is not working.I have got a button on client side thats starting timer with same code. So its working with a button on client side but not working if this command come from server.Whats the problem ??
Here is my codes ;
void MessageSend(string msj)
{
foreach (Client _client in connectedCompList)
{
//for sending data from server side to client side
_client.clientSoket.Send(ConvertByteArray(msj));
}
}
private void btnStartExam_Click(object sender, EventArgs e)
{
MessageSend("/t/" + "," + txtMinute.Text + "," + txtSecond.Text+",");
}
void MessageControl(string message)
{
if (message.Length < 1)
return;
switch (message.Substring(0, 3))
{
case "/e/":
txtAdayNo.Text = "";
txtVeri.Text = "";
txtAdSoyad.Text = "";
txtSinav.Text = "";
break;
case "/t/":
// starting exam after separate min and sec.
string[] time = message.Split(',');
minute = Convert.ToInt32(time[1]);
second = Convert.ToInt32(time[2]);
timer.Enabled = true;
timer.Start();
break;
default:
break;
}
private void btnTest_Click(object sender, EventArgs e)
{
// working with this event.
timer.Enabled = true;
timer.Start();
}
If the timer is a
Windows.Forms.Timer, you’ll need to callControl.Invoketo marshal the call that sets the timer properties and starts the timer back on the UI thread.You should also do this for all of your text box and other UI elements. I suspect this is your problem, since socket communication typically occurs on a ThreadPool thread and not on the main (UI) thread.