通过线程VB.net的进度条未更新

时间:2017-10-20 08:49:02

标签: wpf vb.net progress-bar

我尝试通过多线程运行进度条,同时运行耗时的代码,但进度条没有更新。以下是我开始新线程的方法:

Private Sub DevelopBtn_Click(sender As Object, e As RoutedEventArgs) Handles SchExport.Click


    Dim excelWB As Excel.Workbook
    Dim ScheduleSht As Excel.Worksheet



    '**********************************Progress Bar*********************

    Dim newWindowThread As System.Threading.Thread = New System.Threading.Thread(AddressOf test)
    newWindowThread.SetApartmentState(ApartmentState.STA)
    newWindowThread.Start()
    '*********************************************************************
    Do something 

以上代码调用的测试子如下:

Public Sub test()
    ' Create And show the Window
    Dim prog As BarProgress1 = New BarProgress1()
    prog.Show()
    '// Start the Dispatcher Processing
    prog.PB1.Visibility = Visibility.Visible
    prog.PB1.IsIndeterminate = False
    For n As Integer = 0 To 100
        Thread.Sleep(100)
        prog.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, Sub()

                                                                                       prog.PB1.Value = 50
                                                                                       prog.TB.Text = n
                                                                                   End Sub)
        prog.PB1.IsIndeterminate = 50
    Next
    prog.Close()
End Sub

代码在WPF中,而prog是包含进度条的另一个窗口,PB1是进度条名称。

非常感谢任何解决问题的帮助。

0 个答案:

没有答案