Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MsftDiscFormat2Data事件处理程序_C#_Imapi - Fatal编程技术网

C# MsftDiscFormat2Data事件处理程序

C# MsftDiscFormat2Data事件处理程序,c#,imapi,C#,Imapi,我已使用Interop.cs成功地将IMAPI2集成到我的应用程序中。我可以毫无问题地刻录CD/DVD。但是,MsftDiscFormat2Data更新的事件处理程序不工作,因此无法移动进度条 以下是我在codeproject网站上找到的代码: 私有void backgroundBurnWorker_DoWork(对象发送方,DoWorkEventArgs e) { MsftDiscRecorder2 discRecorder=null; MsftDiscFormat2Data discForm

我已使用Interop.cs成功地将IMAPI2集成到我的应用程序中。我可以毫无问题地刻录CD/DVD。但是,MsftDiscFormat2Data更新的事件处理程序不工作,因此无法移动进度条

以下是我在codeproject网站上找到的代码:

私有void backgroundBurnWorker_DoWork(对象发送方,DoWorkEventArgs e) { MsftDiscRecorder2 discRecorder=null; MsftDiscFormat2Data discFormatData=null

        try
        {
            //
            // Create and initialize the IDiscRecorder2 object
            //
            discRecorder = new MsftDiscRecorder2();
            var burnData = (BurnData)e.Argument;
            discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId);

            //
            // Create and initialize the IDiscFormat2Data
            //
            discFormatData = new MsftDiscFormat2Data
                {
                    Recorder = discRecorder,
                    ClientName = ClientName,
                    ForceMediaToBeClosed = _closeMedia
                };

            //
            // Set the verification level
            //
            var burnVerification = (IBurnVerification)discFormatData;
            burnVerification.BurnVerificationLevel = _verificationLevel;

            //
            // Check if media is blank, (for RW media)
            //
            object[] multisessionInterfaces = null;
            if (!discFormatData.MediaHeuristicallyBlank)
            {
                multisessionInterfaces = discFormatData.MultisessionInterfaces;
            }

            //
            // Create the file system
            //
            IStream fileSystem;
            if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem))
            {
                e.Result = -1;
                return;
            }

            //
            // add the Update event handler
            //
            discFormatData.Update += discFormatData_Update;

            //
            // Write the data here
            //
            try
            {
                discFormatData.Write(fileSystem);
                e.Result = 0;
            }
            catch (COMException ex)
            {
                e.Result = ex.ErrorCode;
                MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed",
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            finally
            {
                if (fileSystem != null)
                {
                    Marshal.FinalReleaseComObject(fileSystem);
                }
            }

            //
            // remove the Update event handler
            //
            discFormatData.Update -= discFormatData_Update;

            if (_ejectMedia)
            {
                discRecorder.EjectMedia();
            }
        }
        catch (COMException exception)
        {
            //
            // If anything happens during the format, show the message
            //
            MessageBox.Show(exception.Message);
            e.Result = exception.ErrorCode;
        }
        finally
        {
            if (discRecorder != null)
            {
                Marshal.ReleaseComObject(discRecorder);
            }

            if (discFormatData != null)
            {
                Marshal.ReleaseComObject(discFormatData);
            }
        }
    }
无效discFormatData_更新([In,MarshalAs(UnmanagedType.IDispatch)]对象发送方,[In,MarshalAs(UnmanagedType.IDispatch)]对象进度) { // //看看我们是否取消了 // if(backgroundBurnWorker.CancellationPending) { var format2Data=(IDiscFormat2Data)发送方; format2Data.CancelWrite(); 返回; }

        var eventArgs = (IDiscFormat2DataEventArgs)progress;

        _burnData.task = BURN_MEDIA_TASK.BURN_MEDIA_TASK_WRITING;

        // IDiscFormat2DataEventArgs Interface
        _burnData.elapsedTime = eventArgs.ElapsedTime;
        _burnData.remainingTime = eventArgs.RemainingTime;
        _burnData.totalTime = eventArgs.TotalTime;

        // IWriteEngine2EventArgs Interface
        _burnData.currentAction = eventArgs.CurrentAction;
        _burnData.startLba = eventArgs.StartLba;
        _burnData.sectorCount = eventArgs.SectorCount;
        _burnData.lastReadLba = eventArgs.LastReadLba;
        _burnData.lastWrittenLba = eventArgs.LastWrittenLba;
        _burnData.totalSystemBuffer = eventArgs.TotalSystemBuffer;
        _burnData.usedSystemBuffer = eventArgs.UsedSystemBuffer;
        _burnData.freeSystemBuffer = eventArgs.FreeSystemBuffer;

        //
        // Report back to the UI
        //
        backgroundBurnWorker.ReportProgress(0, _burnData);
    }
不幸的是,更新处理程序从未被调用。我在互联网上到处查找,但找不到解决方案。我看到一些人有同样的问题,但没有人能够回答

Eric的原始代码, 因为某种原因,它确实起作用


有人能帮我吗?

我知道,为时已晚,但我在更新回调中遇到了同样的问题


打开Project->Properties->Application->Assembly Information并勾选“Make Assembly COM visible”。

这是答案吗?如果是,请展开它。如果不是,请删除它。哇!!!!你刚刚帮我解决了一个我一个月来一直试图解决的问题!!!谢谢你,新年快乐!这为我解决了这个问题。