【问题标题】:Async Page Asp.net webforms threads异步页面 Asp.net 网络表单线程
【发布时间】:2013-08-02 07:55:09
【问题描述】:

我想解决我遇到的一个特定问题,所以这个问题更有可能是一个讨论。

基本上,有一个带有 WebForm1.aspx 的 asp.net 项目,上面有一个按钮。一旦客户按下按钮,就会启动一个线程,然后,就会有一个像这样的 Response.Redirect:

protected void Button1_Click(object sender, EventArgs e)
{
    BL.Class1 cd = new BL.Class1();
    cd.Run(); // or cd.AsyncRun();
    Response.Redirect("~/WebForm2.aspx",true);
}

当然,一切都应该是非静态的。业务逻辑类看起来像这样:

 public class Class1
 {
    public int Signal = 0;
    // non blocking Run... the webserver continues with this process running backwards
    public void RunAsync()
    {
        Signal = 0;
        new System.Threading.Thread(() =>
        {
            System.Threading.Thread.Sleep(100000); // simulate heavy task!
        }
        ).Start();
        Signal = 1;
    }

    // blocking Run...
    public void Run()
    {
        Signal = 0;
        System.Threading.Thread.Sleep(100000); // simulate heavy task!
        Signal = 1;
    }
}

考虑到这一点,下面是讨论: - 在 WebForm2.aspx 中,我想从客户端(javascript/ajax/nonstatic webservice)或服务器到客户端(使用 scriptmanager 的 registerscript)汇集,以便在之后将“Signal”变量设置为“True”繁重的过程..并告诉用户(通过红色背景到绿色的div)或其他内容。 - 如果是这样,如果我不想使用 SignalR 或 Node.js 或 WebApi 或 WebSockets jet,最好的方法是什么? - 您是否有任何文档、书籍可以在 MVC 项目方法中解释这种情况?

所有社区,非常感谢在这个问题上提供帮助。

br,

【问题讨论】:

    标签: asp.net ajax multithreading asynchronous webforms


    【解决方案1】:

    听起来像一个简单的元刷新就可以解决问题,或者一个以设定的时间间隔重新加载页面的 JavaScript - 如果您不想这样做,则不需要任何花哨的东西。

    根据繁重作业的完成状态,使用红色或绿色 div 简单地呈现页面(服务器端)。

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 2019-11-10
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 2011-10-26
      • 2015-12-21
      相关资源
      最近更新 更多