Hi,
I am getting to get the timer job last run time and displaying on the user control.
For this i am using the method as below
But i am not getting the exact lastruntime of timer job.
I tried to use DateTime.Now but problem is it is getting machine time who is running the job.
I am expecting the last run time of timer job of application server where it is running.
Please let me know if i can change anything in the below line
LastRunTime = e.LastRunTime.ToString(),
private List<JobInfo> PopulateJobInfo()
{
SPWebApplication webApp = default(SPWebApplication);
List<JobInfo> jobs = default(List<JobInfo>);
try
{
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
webApp = site.WebApplication;
//SPSite currentSite = webApp.Sites[0] as SPSite;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
jobs = webApp.JobDefinitions.Where(e => e.Name =="TasktoStore" || e.Name == "BubbleTasks").
Select(e => new JobInfo()
{
JobID = e.Id,
JobName = e.Title,
JobDescription = e.Description,
LastRunTime = e.LastRunTime.ToString(),
JobStatus = e.Status == SPObjectStatus.Online ? true: false,
JobStatusText = e.Status.ToString(),
Job = e,
ContentDatabaseID = site.ContentDatabase.Id
}).ToList();
});
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Thanks & Regards, Sudheer