簡體   English   中英

如何在Asp.net網站中添加程序集引用以使用Quartz?

[英]How to add assembly reference to use Quartz in Asp.net Website?

我正在VS 12中的網站上工作,我需要在應用程序啟動時安排一些任務,因為我使用的是石英2.0.0,但出現以下錯誤:

在此處輸入圖片說明

我的網站是在線托管的。

作業調度程序類:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Quartz;
using Quartz.Impl;


public class jobscheduler
{
    public static void Start()
    {
        IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
        scheduler.Start();

        IJobDetail job = JobBuilder.Create<Class2>().Build();

        ITrigger trigger = TriggerBuilder.Create()
            .WithIdentity("trigger1", "group1")
            .StartNow()
            .WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever())
            .Build();

        scheduler.ScheduleJob(job, trigger);
    }
}

我要安排的工作:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Quartz;
using System.Data;
using System.Data.SqlClient;

public class Class2: IJob
{
    public void Execute(IJobExecutionContext context)
    {
        Class1 obj = new Class1();
        DataSet ds;
        ds = new DataSet();
        ds = obj.selecturls();    

        Random ran = new Random();
        int index = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add1 = ds.Tables[0].Rows[index]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add1"] = add1;
        int index2 = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add2 = ds.Tables[0].Rows[index2]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add2"] = add2;
        int index3 = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add3 = ds.Tables[0].Rows[index3]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add3"] = add3;
        int index4 = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add4 = ds.Tables[0].Rows[index4]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add4"] = add4;
        int index5 = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add5 = ds.Tables[0].Rows[index5]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add5"] = add5;
        int index6 = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add6 = ds.Tables[0].Rows[index6]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add6"] = add6;
        int index7 = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add7 = ds.Tables[0].Rows[index7]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add7"] = add7;
        int index8 = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add8 = ds.Tables[0].Rows[index8]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add8"] = add8;
        int index9 = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add9 = ds.Tables[0].Rows[index9]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add9"] = add9;
        int index10 = ran.Next(ds.Tables[0].Rows.Count - 1);
        string add10 = ds.Tables[0].Rows[index10]["urls"].ToString();
        System.Web.HttpContext.Current.Session["add10"] = add10;
    }
}

Global.asax文件:

<%@ Application Language="C#" %>
<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        jobscheduler.Start();
        // Code that runs on application startup
    }

    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown
    }

    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs
    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
    }
</script>

而且我沒有任何assemblyinfo.cs文件,因為我選擇了一個空網站而不是新項目。

如果您從互聯網上下載了Quartz 2.0.0,則必須檢查dll的屬性(在Windows資源管理器->屬性中右鍵單擊該dll)。 您可能必須取消阻止庫:

在此處輸入圖片說明

您可以在該線程中找到另一種可能的解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM