Notes
![]() ![]() Notes - notes.io |
using System.Globalization;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace TimerApp
{
class Program
{
// Windows API kullanarak alarmı tetiklemek için gerekli tanımlamalar
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetSystemTime(ref SYSTEMTIME st);
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public ushort Year;
public ushort Month;
public ushort DayOfWeek;
public ushort Day;
public ushort Hour;
public ushort Minute;
public ushort Second;
public ushort Milliseconds;
}
static void Main()
{
Console.WriteLine("Timer - Calendar-like app");
// Dil ayarlarını Türkçe olarak belirleme (isteğe bağlı)
Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("tr-TR");
Console.WriteLine("Enter the time for the timer (e.g. 1s20dk, 40mins):");
string timeInput = Console.ReadLine();
TimeSpan timeSpan;
if (TryParseTurkishTimeSpan(timeInput, out timeSpan))
{
Console.WriteLine("Timer started: " + timeSpan);
// Zamanlayıcıyı başlat
CountdownTimer(timeSpan);
// Timer sona erdiğinde alarmı tetikle
TriggerAlarm();
}
else
{
Console.WriteLine("Invalid time format");
}
Console.ReadKey();
}
// Türkçe zaman biçimini analiz etmek için özel işlev
static bool TryParseTurkishTimeSpan(string input, out TimeSpan timeSpan)
{
// Regex kullanarak saat, dakika ve saniye değerlerini alın
// Gerekirse daha karmaşık bir Regex deseni kullanabilirsiniz
string pattern = @"(d+)s*[sS](d+)s*[dD][kK]";
var regex = new Regex(pattern);
var match = regex.Match(input);
if (match.Success)
{
int minutes = int.Parse(match.Groups[1].Value);
int seconds = int.Parse(match.Groups[2].Value);
timeSpan = new TimeSpan(0, minutes, seconds);
return true;
}
timeSpan = TimeSpan.Zero;
return false;
}
static void CountdownTimer(TimeSpan timeSpan)
{
var totalSeconds = (int)timeSpan.TotalSeconds;
while (totalSeconds > 0)
{
Console.WriteLine("Time remaining: " + TimeSpan.FromSeconds(totalSeconds));
// 1 saniye beklet.
Thread.Sleep(1000);
totalSeconds--;
}
Console.WriteLine("Time's up!");
}
static void TriggerAlarm()
{
// Sistem saatiyle oynamak için gereken izinleri al
var p = new System.Security.Permissions.RegistryPermission(System.Security.Permissions.PermissionState.Unrestricted);
p.Assert();
// Şu anki zamanı al ve bir alarm süresi ayarla (5 saniye ileri)
var alarmTime = DateTime.Now.AddSeconds(5);
// Windows alarmını tetikleme
var systemTime = new SYSTEMTIME
{
Year = (ushort)alarmTime.Year,
Month = (ushort)alarmTime.Month,
DayOfWeek = (ushort)alarmTime.DayOfWeek,
Day = (ushort)alarmTime.Day,
Hour = (ushort)alarmTime.Hour,
Minute = (ushort)alarmTime.Minute,
Second = (ushort)alarmTime.Second,
Milliseconds = (ushort)alarmTime.Millisecond
};
SetSystemTime(ref systemTime);
Console.WriteLine("Alarm triggered!");
}
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team