WMPLib.dll 未正确运行 Dispose()。如何在 Windows Mobile 上播放 mp3?
使用 Interop.WMPLib.dll 在 Windows Mobile 6.x 上播放 mp3 文件,但我无法让 GC 干净地自行处理。对于一个长时间运行的应用程序(一小时或更长时间),我需要每 5 分钟播放一段短 mp3(20-30 秒),因此我不能让 GC 正确处理该库。 SO 上讨论了一种解决方案(为什么这个简单的移动表单在使用播放器时没有关闭),作者:@ajhvdb,但这对我来说不是一个足够好的解决方案,因为计时器黑客不一致(我有时需要使用 10,000 的计时)或更多)。
有人可以推荐一种更好的处理 Dispose() 的方法,或者只是我可以使用 Windows Mobile 6.x 播放 mp3 文件的另一种方法吗?
我目前拥有的(感谢@ajhvdb)是:
public void Dispose()
{
try
{
Stop();
}
catch (Exception)
{
}
// need this otherwise the process won't exit?!
try
{
int ret = Marshal.FinalReleaseComObject(myPlayer);
}
catch (Exception)
{
}
myPlayer = null;
GC.Collect();
//If you don't do this, it will not quit
//http://www.eggheadcafe.com/software/aspnet/31363254/media-player-freezing-app.aspx
for (int s = 0; s < 100; s++)
{
Application.DoEvents();
Thread.Sleep(1);
}
GC.WaitForPendingFinalizers();
//MessageBox.Show("Application Exiting");
}
Using the Interop.WMPLib.dll to play mp3 files on Windows Mobile 6.x, but I can't get the GC to cleanly dispose of itself. I need to play a short mp3 (20-30 seconds) every 5 minutes for a long-running app (one hour or more), so I cannot afford to not have the GC dispose of the lib correctly. One solution was discussed on SO (Why is this simple Mobile Form not closed when using the player) by @ajhvdb but it is not a good enough solution for me, because the timer hack is not consistent (I needed to sometimes use timings of 10,000 or more).
Can someone recommend a better way of handling Dispose() or just another way I can get mp3 files playing with Windows Mobile 6.x?
What I currently have (thanks to @ajhvdb) is:
public void Dispose()
{
try
{
Stop();
}
catch (Exception)
{
}
// need this otherwise the process won't exit?!
try
{
int ret = Marshal.FinalReleaseComObject(myPlayer);
}
catch (Exception)
{
}
myPlayer = null;
GC.Collect();
//If you don't do this, it will not quit
//http://www.eggheadcafe.com/software/aspnet/31363254/media-player-freezing-app.aspx
for (int s = 0; s < 100; s++)
{
Application.DoEvents();
Thread.Sleep(1);
}
GC.WaitForPendingFinalizers();
//MessageBox.Show("Application Exiting");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用MSDN 文章中的 AxHost 内容?如果是这样,则其中存在错误,导致对象没有被彻底摧毁。
Are you using the AxHost stuff from the MSDN article? If so, there's a bug in it that causes objects to not get cleanly destroyed.