【问题标题】:How to run some operations in background and show a progress bar如何在后台运行一些操作并显示进度条
【发布时间】:2014-01-16 02:04:09
【问题描述】:

所以我得到的是它查看文件是否存在然后打开它然后我想将文件保存为字符串作业我想在后台运行它并且也没有任何窗口弹出并且也许显示一个进度条?

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    Dim job As String
    Dim wo As String
    Dim fpath As String

    fpath = "U:\Output\REV B Template Program Info.xlsm"
    job = InputBox("Please enter the job number.")
    wo = InputBox("Please enter the work order number.")

    If My.Computer.FileSystem.FileExists(fpath) Then
        MsgBox("File found.")
        Process.Start(fpath)

        'I then wanna Save As the sting job
        'I would also like to do it in the back ground and not have it show up
        'and also show a Progress Bar if we can.
    Else
        MsgBox("File not found.")
    End If

End Sub

【问题讨论】:

    标签: vb.net file-io progress-bar


    【解决方案1】:

    就进度而言,您无法显示无法衡量的进度。您的外部流程不会报告进度,因此您无法衡量它,因此您无法显示它。您可能会考虑将其 Style 设置为 Marquee 的 ProgressBar,以指示正在发生的事情,但不是它正在发生的位置。

    如果您想知道进程何时完成,如果您不介意阻塞当前线程或处理其 Exited 事件,则可以在进程上调用 WaitForExit。

    要配置新进程的运行方式,请创建一个 ProcessStartInfo 对象,对其进行适当配置,然后将其传递给 Process.Start 调用。

    【讨论】:

    • 我应该补充一点,我不知道您对保存部分的意思。您要保存的究竟是什么?是过程的输出吗?
    • 这样做是打开一个 Excel 模板,我想要它做的是,文件另存为,工作并且没有任何框弹出。
    • 在这种情况下,您需要研究 Excel 自动化,并在代码中直接使用 Excel COM 对象,而不是生成外部独立进程。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-29
    相关资源
    最近更新 更多