Heading Here
I have a button
when i press it the following event starts
that records from the microphone
I want the while loop to stop after a certain time so i added a tick event
from what i know after stating the tick is should take one tick ( 50 milisec in this case)
to trigger the event
but nothing happens and i am stuck in an endless loop
this is the code:
public void StartRecording()
{
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = TimeSpan.FromMilliseconds(50);
dt.Tick += new EventHandler(dt_Tick);
if (microphone == null)
{
microphone = Microphone.Default;
microphone.BufferDuration = TimeSpan.FromMilliseconds(1000);
buffer = new byte[microphone.GetSampleSizeInBytes(
microphone.BufferDuration)];
var _sampleRate = microphone.SampleRate;
}
_stopRequested = false;
if (dt.IsEnabled == false)
dt.Start();
while (_stopRequested == false)
{
microphone.Start();
microphone.GetData(buffer);
Buf_total_len = +buffer.Length;
data.Add(buffer);
}
}
private void dt_Tick(object sender, EventArgs e)
{
_stopRequested = true;
}