0

私はasp.net MVC-5 Webアプリケーションに取り組んでおり、nugetを使用してhangfireツールをインストールしました:-

Install-Package Hangfire

しかし、アプリケーションを実行すると、この例外が発生しました:-

The following errors occurred while attempting to load the app.
 - No assembly found containing an OwinStartupAttribute.
 - No assembly found containing a Startup or [AssemblyName].Startup class.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config. 

2番目の質問。上記のエラー修正を取得した場合、hangfire を使用して定義済みの間隔でアクション メソッドを呼び出す方法を教えてください。現在、私は glabal.asax 内でこれを次のように定義しています:-

static void ScheduleTaskTrigger()
        {
            HttpRuntime.Cache.Add("ScheduledTaskTrigger",
                                  string.Empty,
                                  null,
                                  Cache.NoAbsoluteExpiration,
                                  TimeSpan.FromMinutes(60)), 
                                  CacheItemPriority.NotRemovable,
                                  new CacheItemRemovedCallback(PerformScheduledTasks));
        }

        static void PerformScheduledTasks(string key, Object value, CacheItemRemovedReason reason)
        {
            //Your TODO
            HomeController h = new HomeController();
            var c = h.ScanServer("12345", "allscan");
            ScheduleTaskTrigger();
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            ScheduleTaskTrigger();
        }

- - 編集 - - - - -

startup.css クラスを追加した後、global.asax 内で次のように定義しました:-

HomeController h = new HomeController();
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
           // ScheduleTaskTrigger();

            RecurringJob.AddOrUpdate(() =>  h.ScanServer("12345","allscan"), Cron.Minutely);
        }

主に、Home コントローラーの下で「ScanServer」という名前のアクション メソッドを呼び出します。現在、ScanServer は次の定義を持つ非同期タスクです:-

public async Task<ActionResult> ScanServer(string tokenfromTMS, string FQDN) 
        {

だから私のglobal.asaxはこのエラーを引き起こしています:-

Async methods are not supported. Please make them synchronous before using them in background.
4

1 に答える 1