|
■No60239 (ワイワイ さん) に返信
BackGroundWorker VB.NETです。
Form1にはBackgroundWorkerのBackgroundWorker1とProgressバーがあります。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim obj1 As New Class1()
obj1.BG = BackgroundWorker1
For i = 0 To 9
obj1.StPer = i * 10
obj1.Exec()
Next
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
Button1.Enabled = True
End Sub
End Class
Public Class Class1
Public Property StPer As Integer
Public Property BG As BackgroundWorker
Public Sub Exec()
For i = 0 To 9
Threading.Thread.Sleep(100) '時間のかかる処理
BG.ReportProgress(StPer + i)
Next
End Sub
End Class
|