0

I am working on a website in VS 12 and I need to schedule some task when the application starts for that I am using quartz 2.0.0 but I am getting the following error:

enter image description here

My website is hosted online.

Job scheduler class:

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);
    }
}

The job which I want to schedule:

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 file:

<%@ 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>

and I don't have any assemblyinfo.cs file because I selected an empty website instead of the new project.

feeeper
  • 2,865
  • 4
  • 28
  • 42
Joe
  • 3
  • 6

1 Answers1

1

If you downloaded Quartz 2.0.0 from the Internet you have to check dll's properties (right click on the dll in windows explorer -> Properties). It's possible that you have to unblock the library:

enter image description here

Another possible solutions you can find in that thread.

feeeper
  • 2,865
  • 4
  • 28
  • 42