Learn from Quartz.net2.0 's experience.

Source: Internet
Author: User

Because the project to apply to this scheduling method, so the time to learn the next, simple usage can grasp the

First, as a person who has not been used, how to use it?

So Baidu has to download the original first

quartz.net2.0,

And then I went down to a quartz.net2.0.

, and then you have to quote Quartz.dll and Common.Logging.dll.

, and finally the config is configured, this simple:

Direct Sticker Code

<configSections>

<section name= "Quartz" type= "System.Configuration.NameValueSectionHandler, System, version=1.0.5000.0,culture= Neutral, publickeytoken=b77a5c561934e089 "/>

</configSections>

<quartz>

<add key= "Quartz.scheduler.instanceName" value= "Exampledefaultquartzscheduler"/>

<add key= "Quartz.threadPool.type" value= "Quartz.Simpl.SimpleThreadPool, quartz"/>

<add key= "Quartz.threadPool.threadCount" value= "ten"/>

<add key= "quartz.threadPool.threadPriority" value= "2"/>

<add key= "Quartz.jobStore.misfireThreshold" value= "60000"/>

<add key= "Quartz.jobStore.type" value= "Quartz.Simpl.RAMJobStore, quartz"/>

</quartz>

These preparations are done, it's the main course.

public void Send_saveinfo ()
{
Get Schema interface Information
IScheduler Scheduler = Factory. Getscheduler ();
Open the Quartz.net architecture
Scheduler. Start ();
Find Writelogjob This Job
Ijobdetail job = jobbuilder.create<writelogjob> (). Withidentity ("Samplejob", "JobGroup1"). Build ();
What time does the job
Itrigger trigger = Triggerbuilder.create (). Startnow (). Build ();
Execute this method at 0 O ' Day
Itrigger trigger = new Crontriggerimpl ("Crontrigger", "TriggerGroup1", "0 0 0 * *?");
Scheduler. Schedulejob (Job, trigger);

}

Execute this method at 0 O ' Day
Itrigger trigger = new Crontriggerimpl ("Crontrigger", "TriggerGroup1", "0 0 0 * *?");
Scheduler. Schedulejob (Job, trigger);

Here's your WinForm or WPF method.

The final note is that the method to add when you exit this page

Stop this service when you want to close the program
IScheduler Scheduler = Factory. Getscheduler ();
if (scheduler! = NULL)
{
Scheduler. Shutdown (TRUE);
}

If you don't add this, you'll get an error if you open it again, unless you stop the service in the process.

Of course, here is just the implementation of the page, by the above we want to build a writelogjob this job, its corresponding name is of course Writelogjob

But to correspond to its interface: IJob

As follows:

public class Writelogjob:ijob
{

Private readonly EcoCementDataBasic.Data.OrderInformationData temporderdata = new Orderinformationdata ();
public void Execute (Ijobexecutioncontext context)
{
Get the current file path
string filelogpath = AppDomain.CurrentDomain.BaseDirectory;

Save the current path under Order information Excel
list<ecocementdatabasic.data.ordermodel> temporderinformation = Temporderdata.excelmodel ();
StreamWriter SW = null;
SaveFileDialog sfd = new SaveFileDialog ();
Specify the path
String path = Saveconfig.getconfigvalue ("Reportfilepath") + "//";

SfD. FileName = "Order Information" + DateTime.Now.ToString ("yyyyMMdd") + ". xls";

Try
{
SW = new StreamWriter (PATH+SFD. Filename.tostring (), false, Encoding.unicode);
String sb = Getgriddetailtablehtml (temporderinformation, 9, "Order Information", DateTime.Now.ToShortDateString ());
Sw. Write (SB);
Sw. Flush ();
Program.get_ilog (). Log (String. Format ("Successfully export report information to Server");

}
catch (IOException IoE)
{
Throw IoE;

}
Finally
{
if (sw! = NULL)
{
Sw. Close ();

}
}

Get path file
String file = Path + SFD. FileName;

Get configuration information for sending messages
Loadconfig ();
SendEmail sendMail = new SendEmail ();
Sendmail.sendmail (Toemail, Fromemail, "This is the current order real-time margin information", "Order Information" +datetime.now.tostring ("Yyyy-mm-dd"), frompwd);
Sendmail.attachments ("+file+");
Sendmail.sendasync (Sendcompletedcallback, Fromsmtpserver, Fromsmtpport);
Sendmail.send (Fromsmtpserver, Fromsmtpport);

Delete data from 1 weeks ago
SfD. FileName = "Order Information" + DateTime.Now.AddDays (-7). ToString ("yyyyMMdd") + ". xls";
if (File.exists (@ "+ sfd). FileName + ""))
{
Delete if it exists
File.delete (@ "" + SFD. FileName + "");
}

}

Note that this is another class built.

Look at the simple scatter:

Learn from Quartz.net2.0 's experience.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.