繁体   English   中英

使用Global.asax中的Application_Start()方法启动后,Web Service冻结

[英]Web Service freezes after startup with Application_Start() method in Global.asax

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

问题在于,Web Service在此方法需要的时间内被冻结,而我的应用程序直到获得此列表后才启动(实际上它已启动,但也被冻结,甚至不显示Form)。

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

Global.asax中的代码:

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM