IMAPI2在VB 2008进度条中

时间:2010-09-23 21:39:30

标签: vb.net cd-burning imapi

我开始制作刻录CD / DVD的程序,一切都很好。 我找到了使用IMAPI2 API刻录的方法,但现在我遇到了问题: 我无法获得燃烧的进度条。 这是代码:

Dim CDD1 As New IMAPI2.MsftDiscMaster2
Dim CDD2 As New IMAPI2.MsftDiscRecorder2

Dim FSI As New IMAPI2FS.MsftFileSystemImage
Dim CDD3 As New IMAPI2.MsftDiscFormat2Data

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Index = 0
    Dim UniqueID = ""
    Dim Directory
    Dim Path = "C:\lll"
    Dim result
    Dim Stream

    Label1.Text = "----- Started -----."

    UniqueID = CDD1.Item(Index)
    Label1.Text = Label1.Text & vbCrLf & "ID found: " & UniqueID

    CDD2.InitializeDiscRecorder(UniqueID)
    Label1.Text = Label1.Text & vbCrLf & "Recorder selected!"

    Directory = FSI.Root
    Label1.Text = Label1.Text & vbCrLf & "Directory is here: " & Directory.ToString

    CDD3.Recorder = CDD2
    Label1.Text = Label1.Text & vbCrLf & "Recorder 2 selected!"

    CDD3.ClientName = "IMAPI2 TEST"
    Label1.Text = Label1.Text & vbCrLf & "Client Name Selected!"

    FSI.ChooseImageDefaults(CDD2)
    Label1.Text = Label1.Text & vbCrLf & "Default selected!"

    Directory.AddTree(Path, False)
    Label1.Text = Label1.Text & vbCrLf & "Directory added!"

    result = FSI.CreateResultImage()
    Stream = result.ImageStream

    Label1.Text = Label1.Text & vbCrLf & "Writing content to disc..."

    If (CDD3.IsCurrentMediaSupported(CDD2) = True) Then
        If (CDD3.IsRecorderSupported(CDD2) = True) Then

            CDD3.Write(Stream)

        Else
            MsgBox("Not Suported Recorder!")
        End If
    Else
        MsgBox("Not Suported Media!")
    End If

    Label1.Text = Label1.Text & vbCrLf & "----- Finished -----"

End Sub

何时命令

CDD3.Write(流)

被触发,程序冻结,并且在数据完全烧毁之前不会响应。

有没有办法阻止这种情况,停止程序冻结并启用进度条?

感谢。

1 个答案:

答案 0 :(得分:1)

您需要使用线程。因此,在按钮单击事件处理程序中,您启动一​​个执行实际刻录的新线程,当它在单独的线程中进行时,主线程可以继续更新GUI(包括您的进度条)。

有关简单示例,请参阅Thread.Start,如果您需要更多信息,我建议您从这里开始:Managed Threading