How to get Sitecore Agent details

If you have scenario to get the details of Sitecore Agents, its last run time and interval to run, below code will help

	Sitecore.Tasks.Scheduler scheduler = new Sitecore.Tasks.Scheduler();
            var agentData  = scheduler.GetType().GetField("m_agents", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).GetValue(scheduler);

            Type schedulerType = typeof(Sitecore.Tasks.Scheduler);
            Type agentType = schedulerType.GetNestedType("Agent", BindingFlags.NonPublic);
            FieldInfo lastrunpro = agentType.GetField("m_lastRun", BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo Name = agentType.GetField("m_name", BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo interval = agentType.GetField("m_interval", BindingFlags.NonPublic | BindingFlags.Instance);

            if (agentData != null)
            {
                var agentCollection = agentData as IEnumerable;

                foreach (object agent in agentCollection)
                {
                    AgentsList.Add(new AgentsInfo() {
                        Name = Convert.ToString(Name.GetValue((agent))).Replace("Sitecore.Tasks.", ""),
                        LastRunTime = Convert.ToString(lastrunpro.GetValue((agent))),
                        Interval = Convert.ToString(interval.GetValue((agent)))
                    });
                }
            }
        }