How to perform regular operations on the website when you use the slots?

On Azure the site is used (the application Service).
To deploy with no interruption to service uses two slots - the new version is filled to the second slot and then switch between the slots.
Once a day you must do some operation to do this when the application starts, runs about the following code
// In Global.asax
protected void Application_Start(){
 // ...
 var t = new Thread(new SomeClass().SomeMethod);
t.Start;
 // ...
}
// In SomeClass
public void SomeMethod(){
 while (true) {
 // Check that it's a new day and do some work
Thread.Sleep(TimeSpan.FromHours(1);
}
}

The code works as it should, always in time, with him no problem.

But, the problem arises from the fact that two of the deployment slot, and therefore work two copies of the site. They work simultaneously, and this operation is performed twice.

Tried to add in parameters for the combat slots application option IsProduction and check it at the start of the task
if (Environment.GetEnvironmentVariable("IsProduction") == null || Environment.GetEnvironmentVariable("IsProduction") != "true") return;

It works, but sometimes, for some reason, does not work, I suspect, after switching between slots. Sometimes after switching between slots of second slot finds himself fighting (IsProduction = true), the code again and is activated twice.

Thought about to add to the site WebJobs, but the problem is that these web tasks are switched along with the slot. I.e. adding a job to one slot after switching, the job goes to the second slot. And since the slot is not used, it is not guaranteed, it can be unloaded from memory along with the web job.

How to properly implement these regular operations only once at the slots?
March 20th 20 at 11:41
1 answer
March 20th 20 at 11:43
There are no special options to use the external for both applications, but common to store: a database, just a file on disk, a third party service, jerking which will be checked one last time to run the task.

Find more questions by tags ASP.NETMicrosoft Azure