从其他类运行ActiveX函数时出现System.AccessViolationException

本文关键字:System AccessViolationException 函数 其他 运行 ActiveX | 更新日期: 2023-09-27 18:25:29

我有这些类:

Form1.cs
服务器.cs

现在当我在Server.cs 中这样做时

form1.startCapture("C:''test.mp4");

然后在Form1.cs 中

public void startCapture(String filename)
    {
       short result = this.axVideoCap1.Start();
    }

然后我得到一个System.AccessViolationException

System.Runtime.InteropServices.COMException was unhandled.
Message = An attempt was made to read or write protected memory. This is often an indication that other memory is corrupt.
Source = mscorlib
Stack Trace:
    at System.RuntimeType.ForwardCallToInvokeMember (String membername, BindingFlags flags, Object target, Int32 [] aWrapperTypes, Message & msgData)
    at VIDEOCAPLib._DVideoCap.Start ()
    at AxVIDEOCAPLib.AxVideoCap.Start ()
...

如何解决此错误?

public void startCapture(String filename)
    {
            this.axVideoCap1.CaptureVideo = this.captureVideoCheckBox.Checked;
            this.axVideoCap1.CaptureAudio = this.captureAudioCheckBox.Checked;
            this.axVideoCap1.ShowPreview = this.showPreviewCheckBox.Checked;
            this.axVideoCap1.UseVideoCompressor = this.useVideoCapCheckBox.Checked;
            this.axVideoCap1.UseAudioCompressor = this.useAudioCapCheckBox.Checked;
            this.axVideoCap1.CaptureMode = true;
            this.axVideoCap1.CaptureFileName = filename;
            this.axVideoCap1.SyncMode = 1;
            short result = this.axVideoCap1.Start();
            switch (result)
            {
                case -1:
                    MessageBox.Show("Capture Failure,Video, Audio Compressor not correct or capture file opening");
                    return;
                case -2:
                    MessageBox.Show("Capture file not found");
                    return;
            }
            this.previewButton.Enabled = false;
            this.captureButton.Enabled = false;
            this.stopButton.Enabled = true;
    }

从其他类运行ActiveX函数时出现System.AccessViolationException

我修复了它,我在Form1中运行了一个无限循环。Form1启动了服务器,服务器访问了Form1。现在我创建了Start.cs,它在第二个线程中启动Server和Form1。

需要一些调用回调