我需要从作为Windows服务运行的C#应用程序中播放wav文件.我已经尝试了System.Media.SoundPlayer和对WinMM.dll的P/Invoke调用(这可能是SoundPlayer正在做的事情).
[DllImport("WinMM.dll")]
private static extern bool PlaySound(string fname, int Mod, int flag);
Run Code Online (Sandbox Code Playgroud)
如果我将我的代码作为控制台应用程序运行,则声音会播放.当我从服务运行它,没有运气,我想我并不感到惊讶.
那么有没有办法从Windows服务播放声音?DirectSound会有帮助吗?或者我是否会被困在编写控制台应用程序并让Windows服务应用程序与它作为中介进行通信?
提前致谢