我正在开发一个简单的应用程序,当我按下“获取读数”按钮时,将听取麦克风并处理基频。我的问题是,当我创建要在DB中记录的数据时,值为0.如果我调试解决方案,我可以看到在插入程序后仍在处理频率。
作为我的应用程序的基础,我正在使用Codeproject(FTGuitarTuner)上提供的代码。
private void getReading_Click(object sender, EventArgs e)
{
StartTime = DateTime.Now;
EndTime = StartTime.AddSeconds(3);
TotalMillisegundos = EndTime.Subtract(StartTime).TotalMilliseconds;
tmr.Start();
tmr.Tick += new EventHandler(tmr_Tick);
StartListenning(device);
while (DateTime.Now <= this.EndTime)
{
isListenning = true;
tmr_Tick(sender, e);
}
StopListenning();
/*Insert na BD*/
insertReadingBD(sender, e);
getBySessaoToolStripButton2_Click(sender, e);
}
其他3个功能是
private void StopListenning()
{
isListenning = false;
frequencyInfoSource.Stop();
frequencyInfoSource.FrequencyDetected -= new EventHandler<FrequencyDetectedEventArgs>(frequencyInfoSource_FrequencyDetected);
frequencyInfoSource = null;
}
private void StartListenning(SoundCaptureDevice device)
{
isListenning = true;
frequencyInfoSource = new SoundFrequencyInfoSource(device);
frequencyInfoSource.FrequencyDetected += new EventHandler<FrequencyDetectedEventArgs>(frequencyInfoSource_FrequencyDetected);
frequencyInfoSource.Listen();
}
void frequencyInfoSource_FrequencyDetected(object sender, FrequencyDetectedEventArgs e)
{
if (InvokeRequired)
{
BeginInvoke(new EventHandler<FrequencyDetectedEventArgs>(frequencyInfoSource_FrequencyDetected), sender, e);
iEscreve = false;
}
else
{
if (e.Frequency > 25.000 && e.Frequency < 4500.000)
{
frequencies.Add(e.Frequency);
updateFreqTxt(e.Frequency);
}
}
}
我的问题是,如何在完成所有处理后只在数据库中插入的方式同步事件?
感谢的!