private TaskCompletionSource<bool> response;
private string _text = "";
public void SetResult(bool result)
{
this.response.SetResult(result);
}
public async Task<bool> SendYesNo()
{
response = new TaskCompletionSource<bool>();
MessageBox.Show(this._text, "", MessageBoxButtons.YesNo);
this._text = "";
return response.Task.Result;
}
I'm using this code which is executed in a JavaScript script file so I can't call the await keyword.
I want to return a boolean after I set it using SetResult
. If the response is not set, it will wait until it's set and will not return anything until it's set. It also has to be asychronous.
How to achieve this without Tasks (as I can't use the await keyword in JavaScript)?