I want to wait for an event when I receive data in my C # project.
When a program reads some GetData data, another program raises an event at the end of reading that data (call EventForGetData). So, I need to wait until EventForGetData is finished.
I wrote this code for this task, but I believe that this code can write more optimal.
public static bool WaitEvent = true;
public void EventForGetData(string variable)
{
WaitEvent = false;
}
public static string ForWaitGetData()
{
WaitEvent = true;
while (WaitEvent)
{
System.Threading.Thread.Sleep(5);
Application.DoEvents();
}
return Variable;
}
public object GetData(){
...
ForWaitGetData();
...
return MyObject;
}
source
share