Hack Forums
[.NET] Timed Button - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Timed Button (/showthread.php?tid=4771848)



Timed Button - KingHank - Apr 10, 2015

So I want to make a button that presses at a time I set, so say I pick 11:00 AM EST, At the exact time the button presses how would i do this? Any video tutorials?


* - Odus - Apr 10, 2015

How about making use of the Windows Task Scheduler and have it run the code of your button event instead of actually simulating a button click?


* - KingHank - Apr 10, 2015

Can you link me a video tutorial? Is there anyway to do it the way i described?


* - Coco_Cubana - Apr 10, 2015

public class Timer1
{
private static System.Timers.Timer aTimer;

public static void Main()
{
// Create a timer with a ten second interval.
aTimer = new System.Timers.Timer(600000);

// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

// Set the Interval to x minutes
aTimer.Interval = 600000;
aTimer.Enabled = true;

Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();

// If the timer is declared in a long-running method, use
// KeepAlive to prevent garbage collection from occurring
// before the method ends.
GC.KeepAlive(aTimer);
}

// Specify what you want to happen when the Elapsed event is
// raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Butnupdate.Enabled = false;
MessageBox.Show("Time Up!");
}
}

example taken from microsoft


* - Jibbe - Apr 10, 2015

Code
If DateTime.Now.ToString = "What you want" Then
      Button1.PerformClick()
      End If
There you go


* - VEX_solutions - Apr 10, 2015

(Apr 10, 2015 09:34 AM)basemanbasil Wrote:  public class Timer1
{
private static System.Timers.Timer aTimer;

public static void Main()
{
// Create a timer with a ten second interval.
aTimer = new System.Timers.Timer(600000);

// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

// Set the Interval to x minutes
aTimer.Interval = 600000;
aTimer.Enabled = true;

Console.WriteLine("Press the Enter key to exit the program.");
Console.ReadLine();

// If the timer is declared in a long-running method, use
// KeepAlive to prevent garbage collection from occurring
// before the method ends.
GC.KeepAlive(aTimer);
}

// Specify what you want to happen when the Elapsed event is
// raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Butnupdate.Enabled = false;
MessageBox.Show("Time Up!");
}
}

example taken from microsoft

This is java code.

As the user above me said that's one of the ways to do it. Just stick that in a timer that checks every few seconds (or less if you wanted)


* - Nikey646 - Apr 10, 2015

(Apr 10, 2015 02:31 PM)VEX_solutions Wrote:  This is java code.

As the user above me said that's one of the ways to do it. Just stick that in a timer that checks every few seconds (or less if you wanted)

No, it's C# why else would it be posted in the .Net Framework Section?