I want to get the name of the active application when my timer stops. After recording 20 seconds, it should show me the current active name of the application. I tried the code. You can see here. But it shows me nothing after stopping the timer.
C # code:
public class Win32wrapper { private System.Timers.Timer pingTimer; private Timer recordTimer; private List<HarvestApp.ProcessInformation> ProcessList = new List<HarvestApp.ProcessInformation>(); [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint processId); private DateTime recordStartTime; public void startTimer(int pingTimerValue=5000, int recordTimerValue=20000) { pingTimer = new System.Timers.Timer(pingTimerValue); pingTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); pingTimer.Interval = pingTimerValue; pingTimer.Enabled = true; recordTimer = new Timer(recordTimerValue); recordTimer.Elapsed += new ElapsedEventHandler(OnRecordEvent); recordTimer.Interval = recordTimerValue; recordTimer.Enabled = true; recordStartTime = DateTime.Now; } private void OnTimedEvent(object source, ElapsedEventArgs e) { Console.WriteLine("The Ping Elapsed event was raised at {0}", e.SignalTime);
source share