简体   繁体   English

为什么我的事件无法在服务中触发?

[英]Why my events don't fire in a service?

I made a windows form application that listens from the microphone and detects sound patrons. 我制作了一个Windows窗体应用程序,该应用程序从麦克风监听并检测声音顾客。

Now i want to do the same but in a service. 现在我想做同样的事情,但是要在服务中。

I use Naudio and this event: 我使用Naudio和此事件:

myWave = new WaveIn();
...
myWave.DataAvailable += new EventHandler<WaveInEventArgs>(myWave_DataAvailable);

At windows form works fine, but the service don't fires the event. 在windows窗体工作正常,但该服务不触发事件。

Does anyone know why? 有人知道为什么吗?

Another question is 另一个问题是

Will my service hear the microphone even when not logged in? 即使未登录,我的服务也能听到麦克风吗?

Thanks! 谢谢!

Edited with new information and using WaveInEvent class: 使用新信息并使用WaveInEvent类进行编辑:

I declare the variable in the class 我在类中声明了变量

public partial class SoundDetector : ServiceBase {
    ... 
    private WaveInEvent myWave;

Set the event in the constructor 在构造函数中设置事件

public SoundDetector()
{
    myWave.DataAvailable += myWave_DataAvailable;

And start recordig in the OnStart 然后在OnStart中启动recordig

protected override void OnStart(string[] args)
{
    myWave.StartRecording();

But the event still stop firing... 但事件仍然停止触发...

改用WaveInEvent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM