VB 2008进度栏中的IMAPI2 [英] IMAPI2 in VB 2008 progress bar

查看:138
本文介绍了VB 2008进度栏中的IMAPI2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I start making program that will burn CD/DVDs, and everything is okay. I found way to burn with IMAPI2 API, but now I have problem: I can't get progress bar of that burning. Here is code:

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(Stream)

被触发,程序冻结,直到数据完全刻录后才响应.

is triggered, program freeze, and don't respond until data is burned completely.

有什么方法可以停止此程序,停止程序冻结并启用进度条吗?

Is there any way to stop this, to stop program freezing and enabling progress bar?

谢谢.

推荐答案

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

You need to use threading. So in your button click event handler you start off a new thread that does the actual burning and while that's going on in it's separate thread, the main thread can continue to update the GUI (including your progress bar).

有关简单示例,请参见 Thread.Start .进一步的信息,我建议从这里开始:托管线程

See Thread.Start for a simple sample and if you want further information I'd suggest starting here: Managed Threading

这篇关于VB 2008进度栏中的IMAPI2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆