Background Worker dan ProgressBar Vb.Net

Belajar Tutorial Vb.Net Pemula : Penggunaan Class Background Worker dan ProgressBar Vb.Net, membuat aplikasi Background Worker dan ProgressBar Vb.Net khusus pemula, tutorial vb.net selengkapnya di sector code

Class Background Worker - Cara penggunaan Class Background Worker dalam aplikasi vb.net memungkinkan developer vb.net untuk melihat prosess data yang sedang berlangsung, serta pengguna aplikasi akan bisa menggunakan aplikasi yang sama dengan melakukan perintah lain dalam waktu yang sama, sehingga penggunaan Background Worker dan ProgressBar Vb.Net akan sangat user friendly dalam aplikasi windows form. simak terus bagaimana cara pembuatan aplikasinya ya..

Aplikasi Sederhana menggunakan Background Worker dan ProgressBar

Buatlah Project baru dengan nama "BackgroundWorker", dan beri beberapa komponen berikut :
Background Worker dan ProgressBar Vb.Net
  1. ProgressBar
  2. button (2 buah)
  3. label
  4. groupbox
  5. bacground worker
Desainlah tampilannya seperti diatas, dan ikuti step by step pembuatan aplikasinya serta tuliskan code berikut :

Deklarasikan waktu untuk Looping

letakkan code berikut dalam class form1.vb
Dim _Loop As Integer = 0

Code untuk Tombol Start

    Private Sub TombolStart_Click(sender _
        As System.Object, e As System.EventArgs) _
        Handles TombolStart.Click
        _Loop = 30
        Me.TombolStart.Enabled = False
        Me.TombolStop.Enabled = True
        BgWorker.RunWorkerAsync()
    End Sub

Code Tombol Batal

    Private Sub TombolStop_Click(sender _
        As System.Object, e As System.EventArgs) _
        Handles TombolStop.Click
        If BgWorker.IsBusy Then
            If BgWorker.WorkerSupportsCancellation Then
                BgWorker.CancelAsync()
            End If
        End If
        Me.TombolStart.Enabled = True
        Me.TombolStop.Enabled = False
    End Sub

Bakground Worker_DoWork()

    Private Sub BgWorker_DoWork(ByVal _
        sender As Object, _
        ByVal e As  _
        System.ComponentModel.DoWorkEventArgs) _
        Handles BgWorker.DoWork

        For x As Integer = 0 To _Loop
            If BgWorker.CancellationPending Then
                e.Cancel = True
                Exit For
            End If
            System.Threading.Thread.Sleep(1000)
            BgWorker.ReportProgress(CInt((x / _Loop) * 100))
            UpdateLabel(Me.Status, _
            FormatPercent(x / _Loop, 2))
        Next
    End Sub

Update ProgressBarr Value

    Private Sub BgWorker_ProgressChanged(ByVal _
         sender As Object, ByVal e As  _
         System.ComponentModel.ProgressChangedEventArgs) _
        Handles BgWorker.ProgressChanged
        Me.ProgressBar1.Value = _
        e.ProgressPercentage
    End Sub

Bakcgorund Worker Complated

    Private Sub BgWorker_RunWorkerCompleted(ByVal _
        sender As Object, ByVal e As  _
        System.ComponentModel.RunWorkerCompletedEventArgs) _
        Handles BgWorker.RunWorkerCompleted
        If e.Cancelled Then
            Me.Status.Text = "Dibatalkan!"
        Else
            Me.Status.Text = "Komplit!"
        End If
    End Sub

Set Label Delegate

    Delegate Sub SetLabelText_Delegate(ByVal _
    [Label] As Label, ByVal [text] As String)

Update Label

    Private Sub UpdateLabel(ByVal _
        [Label] As Label, ByVal [text] As String)
        If [Label].InvokeRequired Then
            Dim MyDelegate As New  _
            SetLabelText_Delegate(AddressOf UpdateLabel)
            Me.Invoke(MyDelegate, New Object() _
            {[Label], [text]})
        Else
            [Label].Text = [text]
        End If
    End Sub
Simpan aplikasi Background Worker dan ProgressBar Vb.Net kamu dan coba jalankan, berikut kami sertakan source code secara lengkapnya :
Public Class Form1
    Dim _Loop As Integer = 0
    Private Sub TombolStart_Click(sender _
        As System.Object, e As System.EventArgs) _
        Handles TombolStart.Click
        _Loop = 30
        Me.TombolStart.Enabled = False
        Me.TombolStop.Enabled = True
        BgWorker.RunWorkerAsync()
    End Sub

    Private Sub TombolStop_Click(sender _
        As System.Object, e As System.EventArgs) _
        Handles TombolStop.Click
        If BgWorker.IsBusy Then
            If BgWorker.WorkerSupportsCancellation Then
                BgWorker.CancelAsync()
            End If
        End If
        Me.TombolStart.Enabled = True
        Me.TombolStop.Enabled = False
    End Sub
    Private Sub BgWorker_DoWork(ByVal _
        sender As Object, _
        ByVal e As  _
        System.ComponentModel.DoWorkEventArgs) _
        Handles BgWorker.DoWork

        For x As Integer = 0 To _Loop
            If BgWorker.CancellationPending Then
                e.Cancel = True
                Exit For
            End If
            System.Threading.Thread.Sleep(1000)
            BgWorker.ReportProgress(CInt((x / _Loop) * 100))
            UpdateLabel(Me.Status, _
            FormatPercent(x / _Loop, 2))
        Next
    End Sub
    Private Sub BgWorker_ProgressChanged(ByVal _
         sender As Object, ByVal e As  _
         System.ComponentModel.ProgressChangedEventArgs) _
        Handles BgWorker.ProgressChanged
        Me.ProgressBar1.Value = _
        e.ProgressPercentage
    End Sub
    Private Sub BgWorker_RunWorkerCompleted(ByVal _
        sender As Object, ByVal e As  _
        System.ComponentModel.RunWorkerCompletedEventArgs) _
        Handles BgWorker.RunWorkerCompleted
        If e.Cancelled Then
            Me.Status.Text = "Dibatalkan!"
        Else
            Me.Status.Text = "Komplit!"
        End If
    End Sub
    Delegate Sub SetLabelText_Delegate(ByVal _
    [Label] As Label, ByVal [text] As String)
    Private Sub UpdateLabel(ByVal _
        [Label] As Label, ByVal [text] As String)
        If [Label].InvokeRequired Then
            Dim MyDelegate As New  _
            SetLabelText_Delegate(AddressOf UpdateLabel)
            Me.Invoke(MyDelegate, New Object() _
            {[Label], [text]})
        Else
            [Label].Text = [text]
        End If
    End Sub

End Class

Video Tutorial Background Worker dan ProgressBar Vb.Net




Silahkan share dan comment jika bermanfaat :)

COMMENTS

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: Background Worker dan ProgressBar Vb.Net
Background Worker dan ProgressBar Vb.Net
Belajar Tutorial Vb.Net Pemula : Penggunaan Class Background Worker dan ProgressBar Vb.Net, membuat aplikasi Background Worker dan ProgressBar Vb.Net khusus pemula, tutorial vb.net selengkapnya di sector code
https://4.bp.blogspot.com/-n84KDt403BM/VkePfO0psgI/AAAAAAAABLQ/Dru3nWRuZfI/s320/bacgroundworker-progressbar-vbnet.png
https://4.bp.blogspot.com/-n84KDt403BM/VkePfO0psgI/AAAAAAAABLQ/Dru3nWRuZfI/s72-c/bacgroundworker-progressbar-vbnet.png
KODE AJAIB
https://www.kodeajaib.com/2015/11/background-worker-dan-progressbar-vbnet.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2015/11/background-worker-dan-progressbar-vbnet.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy