I developed an application with Windows Forms using C#(visual studio 2010). This application should connect to a server and get data, then process that data.
public partial class Form1 : Form
{
public string Result = "";
MyServer server = new MyServer();
public Form1()
{
InitializeComponent();
server.RecieveMessage += new MyServer.RecieveMessageEventHandler(server_RecieveMessage);
}
void server_RecieveMessage(object sender, string message)
{
Result = message;
}
public string SendCommand(string Command)
{
server.Send(Command);
//wait untill RecieveMessage event raised
//process Data is recieved
server.Send(AnotherCommand);
//wait untill RecieveMessage event raised
//process Data is recieved
....
//till i get what i want
return Result;
}
So I want to wait after server.Send(Message)
until I get the result on event. Sometimes it takes 4 to 5 seconds until I get the result. What do I have to do?