38 lines
914 B
C#
38 lines
914 B
C#
|
|
///
|
|||
|
|
/// 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();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Invokes one beep in a separate thread (non-blocking function)
|
|||
|
|
/// </summary>
|
|||
|
|
public static void Beep()
|
|||
|
|
{
|
|||
|
|
signalBeep.Set();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|