单击其他按钮时停止执行按钮单击

时间:2017-02-25 06:28:28

标签: c# asp.net webforms

考虑以下两个按钮点击事件,我想输出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.

1 个答案:

答案 0 :(得分:0)

不幸的是,我不认为这在一般情况下是可能的。想象一下,您的项目与SO一样大,您使用许多服务器的农场来处理用户。不同的点击次数可能很容易到达不同的服务器。

我能想象的任何解决方案要么不是那么简单,要么不能正常工作,例如,如果用户有多个标签。

你可以做的最好的事情可能是

  • 介绍一些后台执行服务

  • 介绍一些正在执行的任务的注册表

  • 立即将新创建的任务的ID返回给浏览器 显示一些进展UI

  • 定期在某个时间间隔询问服务器完成任务

  • 当用户点击取消时,将任务的ID传递给服务器 要求您的服务停止按ID执行该任务。

相关问题