CallAnAsyncMethod , ( , , ), .
If you have no control over the architecture that forces you to do this code asynchronously, you will need to control the variable and the loop to wait for it to complete.
bool myBool;
bool retrievingMyBool;
RetrieveABoolean(5);
public bool RetrieveABoolean(int id)
{
client.CallAnAsyncMethod(id);
retrievingMyBool = true;
while (retrievingMyBool)
{
Thread.Sleep(100);
}
}
private void completedEventHandler([[parameters go here]])
{
myBool =
retrievingMyBool = false
}
This is a terrible decision, and in the future you will encounter giant headaches, especially if you ever need code that should be thread safe, but it can work as a hack.
source
share