Window Media Player + c#中的内存泄漏 [英] Memory Leaks in Window Media Player + c#
本文介绍了Window Media Player + c#中的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到同样的问题:
Window Media Player + c#中的内存泄漏 [ ^ ]
是否有解决方案,因为上述解决方案不起作用。
内存永远不会释放,直到系统内存不足崩溃
I have the same problem like here:
Memory Leaks in Window Media Player + c#[^]
Is there a solution since the mentioned solution does not work.
The memory is never freed until the system runs out of memory an crashes
推荐答案
我添加了对以下两个dll的引用:
C:\ Windows \ System32 \ wmp.dll
C:\Program Files(x86)\ Microsoft Visual Studio 11.0 \Common7 \IDE \ PrivateComponent \ AxInterop .WMPLib.dll
I added a reference to the following two dlls:
C:\Windows\System32\wmp.dll
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\AxInterop.WMPLib.dll
using AxWMPLib;
private void Form1_Load(object sender, EventArgs e)
{
Console.WriteLine("Test WMP Control");
this.Closing += new CancelEventHandler(this.Form1_Closing); // Set EventHandler
}
AxWMPLib.AxWindowsMediaPlayer wmp = null; // Declare wmp Control
private void InitiateWMP()
{
string link = @"C:\Users\MM\Videos\Video\lighthouse.mpg";
wmp = new AxWMPLib.AxWindowsMediaPlayer();
wmp.Enabled = true;
wmp.Location = new System.Drawing.Point(0, 0);
wmp.Name = "wmp";
wmp.Size = new System.Drawing.Size(800, 600);
this.Controls.Add(wmp);
wmp.URL = link;
}
public void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// Dispose of the Windows Media Player as the form is closing
//
// Note: The Form.Closed and Form.Closing events are not raised when the
// Application.Exit method is called to exit an application.
// If Application.Exit is to be used, you should call the Form.Close method
// before calling the Application.Exit method.
//
if (this.Controls.ContainsKey ("wmp"))
{
this.Controls.RemoveByKey("wmp"); // Remove from Conrols collection
wmp.close(); // Close the Windows Media Player control
wmp.Dispose(); // Dispose
wmp = null;
}
GC.Collect(); // Start .NET CLR Garbage Collection
GC.WaitForPendingFinalizers(); // Wait for Garbage Collection to finish
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
InitiateWMP();
}
这篇关于Window Media Player + c#中的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文