Last active
January 14, 2025 10:30
-
-
Save tkojitu/a83edb4c6adc3220e2a0a7b34a2e3f8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Timers; | |
using System.Threading; | |
public class Example | |
{ | |
private System.Timers.Timer aTimer; | |
private int count = 0; | |
private Thread thread = Thread.CurrentThread; | |
public static void Main() | |
{ | |
new Example().Demo(); | |
} | |
private void Demo() | |
{ | |
SetTimer(); | |
try | |
{ | |
Thread.Sleep(1000 * 60); | |
} | |
catch (ThreadInterruptedException e) | |
{ | |
aTimer.Stop(); | |
aTimer.Dispose(); | |
} | |
} | |
private void SetTimer() | |
{ | |
aTimer = new System.Timers.Timer(1000); | |
aTimer.Elapsed += OnTimedEvent; | |
aTimer.AutoReset = true; | |
aTimer.Enabled = true; | |
} | |
private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e) | |
{ | |
++count; | |
if (count >= 5) | |
{ | |
thread.Interrupt(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great for Group Play
I often play heardle with my friends, and it turns into a fun group activity. We take turns trying to guess the song, and it’s amazing how different people have different areas of music knowledge. It’s a great way to bond and have fun together.