【问题标题】:Web Service freezes after startup with Application_Start() method in Global.asax使用 Global.asax 中的 Application_Start() 方法启动后,Web 服务冻结
【发布时间】:2023-03-30 05:16:01
【问题描述】:

我正在使用一个 Web 服务方法返回一个列表,该列表在我的 Web 服务启动后执行了大约 40 秒(该方法从Global.asax 中的Application_Start() 事件启动)。

问题是 Web 服务在此方法需要的时间内被冻结,并且我的应用程序在获得此列表之前不会启动(实际上它会启动,但也被冻结,甚至不显示表单)。

有什么办法可以解决吗?也许在Application_Start() 中异步调用这个方法?任何帮助将不胜感激。

Global.asax 中的代码:

protected void Application_Start(object sender, EventArgs e)
    {
        WebService WS = new WebService();
        WS.RecursiveFileProcessor();
    }

【问题讨论】:

    标签: c# forms web-services global-asax


    【解决方案1】:

    您可以将该机制作为单独的任务启动:

    protected void Application_Start(object sender, EventArgs e)
    {
        Task.Factory.StartNew(() => 
        {
            WebService WS = new WebService();
            WS.RecursiveFileProcessor();
        });
    }
    

    这应该会停止您的服务挂起。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多