C
C#2y ago
Ely

❔ How do I look a bool method every 5 minutes?

So I have a bool method called WindowWatch(), and it works and returns true and false when I need it to. How do I make it so that I do it every 5 minutes? I feel like I'm not using the boolean method properly. Basically what I am trying to do is run WindowWatch() every five minutes. Code: https://pastebin.com/tvhXgY6k
Pastebin
using System.Reflection;using System.Runtime.InteropServices;using ...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
3 Replies
thevoncarstein
1. You could use Timer class:
var _timer = new System.Timers.Timer(300000); // 5 minutes in milliseconds
_timer.Elapsed += new ElapsedEventHandler(WindowWatch);
_timer.Enabled = true;
var _timer = new System.Timers.Timer(300000); // 5 minutes in milliseconds
_timer.Elapsed += new ElapsedEventHandler(WindowWatch);
_timer.Enabled = true;
And set _timer.Enabled = false to stop. 2. Set WindowWatch to void. If you want to return something, make an Action<bool> callback instead.
TheBoxyBear
TheBoxyBear2y ago
I'm also surprised you need to go this low level importing the DLL. You'd think there would be a Net api for this, maybe in NuGet
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.