How to handle case, where user might hit the button, which invokes long running async operation, multiple time.
My idea was first check if the async operation is run
Why not follow the BackgroundWorker pattern and break out of the loop in DrawContent?
private bool _cancelation_pennding=false;
private delegate DrawContentHandler(TimePeriod period, Token token)
private DrawContentHandler _dc_handler=null;
.ctor(){
this._dc_handler=new DrawContentHandler(this.DrawContent)
}
public void CancelAsync(){
this._cancelation_pennding=true;
}
public void Draw(){
this._dc_handler.BeginInvoke(this.TimePeriod, this.cts.Token)
}
private void DrawContent(TimePeriod period, Token token){
loop(){
if(this._cancelation_pennding)
{
break;
}
//DrawContent code here
}
this._cancelation_pennding=false;
}