Reccuring Jobs - How to know if a Recurring job is running


I have to show if my recurring jobs are running.
The dashboard allows to see it, so I assume that it is possible via the code.



I do like this

using (var connection = JobStorage.Current.GetConnection())
    string lastRunResult = string.Empty;
    var recurringJobs = connection.GetRecurringJobs();
    var job = recurringJobs.FirstOrDefault(p => p.Id.Equals(package.PackageName, StringComparison.InvariantCultureIgnoreCase));
    if (job != null)
            var jobState = connection.GetStateData(job.LastJobId);
            lastRunResult = jobState.Name; // For Example: "Succeeded", "Processing", "Deleted"
        catch ()
            //job has not been run by the scheduler yet, swallow error

If lastRunResult is “Processing”, it is running
(i dont run this exact code, but close enough)

I hope it helps.
It might not be the “correct” way to do it, but it works for me.