如何取消C#中的BeginInvoke操作
要取消C#中的BeginInvoke操作,可使用EndInvoke方法,并在调用BeginInvoke后立即调用EndInvoke方法。例如:
IAsyncResult result = this.BeginInvoke(new Action(() => { }));
this.EndInvoke(result);
另外,也能够使用CancellationToken来取消BeginInvoke操作。例如:
CancellationTokenSource cts = new CancellationTokenSource();
CancellationToken token = cts.Token;
this.BeginInvoke(new Action(() => {
if (token.IsCancellationRequested)
{
return;
}
// 履行需要取消的操作
}), token);
// 取消操作
cts.Cancel();
tiktok粉丝购买:https://www.smmfensi.com/
TOP