Get an instance of the scheduler that is being run on a Windows service

前端 未结 2 1944
攒了一身酷
攒了一身酷 2020-12-18 13:09

Let us say I have prepared my Quartz.NET as a Windows service and it is currently being run (with an ADOJobStore running on Sqlite). I need to take

2条回答
  •  清酒与你
    2020-12-18 13:41

    Starting and stopping the Windows service is not related to Quartz. There seems to be a .NET API for that, but I'm not familiar with it.

    As for adding and removing jobs. You won't get the instance of the Windows service's scheduler. There are two ways to work around it.

    1. Define a WCF contract and host a WCF service in your Windows service. It's pretty straightforward. You don't need IIS nor HTTP. I recommend the TCP binding in this case.
    2. Since you're already using a ADO job store, you can set up both Windows app and Windows service as a Quartz cluster:

    Add

    
    

    to both app and web configs. If I remember correctly, no additional code is required. Additionally you prevent the Windows app form executing a job by setting up a zero-size thread pool:

    
    

    Now, you instantiate a scheduler in your Windows app and use it to add and remove jobs. The jobs will be stored in the ADO job store and picked up by the Windows service. Both app and service must have the same ADO job setore configured, obviously, and the Windows app must have access to the sqlite db.

    One more thing. Using the second approach you won't be able to interrupt a running job form the Windows app.

提交回复
热议问题