2014-02-13 54 views
1

我在ASP.NET MVC 4项目中使用Fluent Scheduler。我想创建一个每天凌晨4点运行的调度程序。这里是我的代码:Fluent调度程序只运行一次

服务

public class ParseService : Registry 
{ 
    public ParseService(string path) 
    { 
     Schedule(() => ParseHelper.ParseData(path)).ToRunEvery(1).Days().At(4, 0); 
    } 
} 

的Global.asax.cs

public class MvcApplication : System.Web.HttpApplication 
{ 
    protected void Application_Start() 
    { 
     AreaRegistration.RegisterAllAreas(); 

     WebApiConfig.Register(GlobalConfiguration.Configuration); 
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
     RouteConfig.RegisterRoutes(RouteTable.Routes); 
     BundleConfig.RegisterBundles(BundleTable.Bundles); 
     AuthConfig.RegisterAuth(); 

     Application["LogPath"] = Server.MapPath("~/Areas/Admin/LogFiles/"); 
     TaskManager.Initialize(new ParseService(Application["LogPath"].ToString())); 
    } 
} 

的问题是,调度只运行一次。如果我想让它在凌晨4点再次运行,我必须重新启动IIS服务器。有人知道我的代码有什么问题吗?请帮帮我。非常感谢。

回答

2

问题是第一次执行它的应用程序池已自动回收。您需要配置应用程序池以保持活动状态,如果这真的是您想要做到的。

这是关于how to configure that的一个很好的教程。

但是,我也同样会在这一点上提醒你。这更适合作为Windows服务或使用Windows任务计划程序启动的控制台应用程序。

+0

感谢您的回答。我赞同你。但是这个库被广泛使用,所以我希望它没有这个错误。你有没有用过它? :( – AnhTriet

+0

@ Forte_201092,有什么错误?没有我没有用过它。 –

+0

调度程序线程如何被回收?如果这个库让这种情况发生,那就很......坏: – AnhTriet