[英]Stop execution of button click when some other button is clicked
考慮以下兩個按鈕點擊事件,我想輸出cancel_click事件來停止hellotest_click事件和重定向的過程
protected async void hellotest_click(object sender, EventArgs e)
{
await Task.Run(() => hello1());
await Task.Run(() => hello2());
}
//if i click another button , say
protected async void cancel_click(object sender, EventArgs e)
{
Response.Redirect(Request.Url.GetLeftPart(UriPartial.Authority) + "/trial/main.aspx", false);
Context.ApplicationInstance.CompleteRequest();
}
// i want the output cancel_click event to stop the process of hellotest_click event and redirect.
不幸的是,我認為這在一般情況下是不可能的。 想象一下,您的項目與SO一樣大,您使用許多服務器的農場來處理用戶。 不同的點擊可能很容易到達不同的服務器
我能想象的任何解決方案要么不那么簡單,要么不能正常工作,例如,如果用戶有多個選項卡。
你可以做的最好的事情可能就是
介紹一些后台執行服務
介紹一些正在執行的任務的注冊表
將新創建的任務的ID立即返回給瀏覽器並顯示一些進度UI
定期在某個時間間隔詢問服務器完成任務
當用戶單擊取消時,將任務的ID傳遞給服務器,並要求您的服務停止按ID執行該任務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.