/// /// Copyright (c) 2021 Sensus Slovensko a.s. /// using System; using System.Threading; namespace Common { public class BackgroundBeep { static Thread beepThread; static AutoResetEvent signalBeep; static BackgroundBeep() { signalBeep = new AutoResetEvent(false); beepThread = new Thread(() => { while (true) { signalBeep.WaitOne(); /// waits for an event Console.Beep(500, 400); /// frequency (Hz), duration (ms) } }, 1); beepThread.IsBackground = true; beepThread.Start(); } /// /// Invokes one beep in a separate thread (non-blocking function) /// public static void Beep() { signalBeep.Set(); } } }