using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private Video myVideo = null;         private void btn_start_Click(object sender, EventArgs e)
        {
            OpenFileDialog openDilg = new OpenFileDialog();
            openDilg.Filter = "All Media Files(*.*)|*.*";
            if (openDilg.ShowDialog() == DialogResult.OK)
            {
                int height = panel1.Height;
                int width = panel1.Width;
                if (myVideo != null)
                {
                    myVideo.Dispose();
                }
                myVideo = new Video(openDilg.FileName, false);
                myVideo.Owner = panel1;
                panel1.Width = width;
                panel1.Height = height;
                myVideo.Play();
                myVideo.Pause();
            }
        }        private void btn_play_Click(object sender, EventArgs e)
        {
            if (myVideo != null)
            {
                myVideo.Play();
            }
        }
    }
}
这是小弟的代码,在运行到myVideo = new Video(openDilg.FileName, false);时会报这个错误:
DLL“C:\WINDOWS\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll”正试图在 OS 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起。哪位高手告诉这是什么意思啊?

解决方案 »

  1.   

    确认Microsoft.DirectX的安装是否有冲突的版本?
      

  2.   

    我刚试过了啊 
    我机器上装得是2000
    而且我安装DirectX的时候没有报什么错误啊?
    怎么检查有没有冲突啊
      

  3.   

    Error Message:LoaderLock was detected
    Message: DLL '.......\Microsoft.DirectX.Direct3D.dll' is attempting 
    managed execution inside OS Loader lock. Do not attempt to run 
    managed code inside a DllMain or image initialization function since
    doing so can cause the application to hang.A Loader lock is one of the Managed Debugging Assistants (MDAs) that were added to VS2005 to help find hard to debug runtime issues. There is code in all Managed DirectX 1.1 assemblies that causes this MDA to fire. Microsoft have confirmed they are aware of the problem. However I do not expect to see a fix for MDX 1.1 since current efforts are focused on MDX2.0/XNA Framework, it ONLY affects code run under the debugger (i.e. it won't happen when users run your EXE) and there is a trivial workaround. I'm not sure of exact reproduction steps - it appears to fire on some projects and not on others.To work around the problem you have several choices:Go back to using VS2003 and .Net 1.1 
    Use MDX 2.0. Note that MDX 2.0 will never actually ship as it is being transformed into the XNA framework. 
    Disable the loader lock MDA. Debug/Exceptions (ctrl-D, E), Open the Managed Debugging Assistants tree node and uncheck Loader Lock. This setting is per solution so it will only affect this solution.