【问题标题】:NAudio, windows service, multithreadingNAudio,Windows服务,多线程
【发布时间】:2015-03-22 21:23:54
【问题描述】:

我有通过 NAudio.dll 播放 *.wav 文件(多线程)的 Windows 服务

    public static void PlayFileBackground(string fileName)
    {
        Task.Run(() => { PlayFile(fileName); });
    }

    private static void PlayFile(string fileName)
    {
        if (File.Exists(fileName) == true)
        {
            try
            {
                var manualResetEvent = new ManualResetEvent(false);
                using (var wfr = new WaveFileReader(fileName))
                using (WaveChannel32 wc = new WaveChannel32(wfr) { Volume = 1, PadWithZeroes = false })
                using (var audioOutput = new DirectSoundOut())
                {
#region play
                    audioOutput.Init(wc);                        
                    audioOutput.Play();
                    audioOutput.PlaybackStopped += (sender, e) => { manualResetEvent.Set(); }; 
                    manualResetEvent.WaitOne();
                    audioOutput.Stop();
#endregion
                }
            }
            catch (Exception exception)
            {                
                logger.Error("Error NAudio.\n{0}", exception.ToString()); //<-never don't catch
            }
        }
    }

如果区域“播放”评论 -> 所有作品

如果区域“播放”未注释 -> 有时我的服务会停止而没有任何错误。

我尝试使用调试器附加,我看到: NAudio.dll 中出现“System.ExecutionEngineException”类型的未处理异常

另外:NAudio.dll 中出现了“System.AccessViolationException”类型的第一次机会异常

有什么想法吗?

【问题讨论】:

标签: c# multithreading windows-services naudio


【解决方案1】:

我找到了替换 DirectSoundOut > WaveOutEvent 的建议。 现在一切正常。谢谢斯图尔特。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 2012-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多