Results 1 to 3 of 3

Thread: [RESOLVED] Backgroundworker and Progressbar

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Resolved [RESOLVED] Backgroundworker and Progressbar

    Hi,

    I have on my form backgroundworker that is running code to make a copy of records. When this operation is start, then I display a Panel and inside panel is Progressbar:

    Attachment 159937

    The reason for using a panel is because I want to display that label "Please wait..." (as in picture above)

    But what is happen is this:

    Attachment 159939

    This is because when that backroundworker is running then it seems that "disables" that label...

    This is what I currently do:

    To start copy operation:

    Code:
    Private Sub MakeCopy_Click(sender As Object, e As EventArgs) Handles MakeCopy.Click
            Select Case MsgBox("Copy """ & (TblTaskContextDataGridView.SelectedRows(0).Cells(2).Value) & """?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Create a Copy?")
    
                Case MsgBoxResult.Yes
                    Me.MyProgressBar.Visible = True
                    Me.TblTaskContextDataGridView.DataSource = Nothing
                    BackgroundWorker1.RunWorkerAsync()
                    Me.Enabled = False
            End Select

    This is where backgroundworker is doing work:

    Code:
    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    
    ‘Code running and making copy......................
     
    End sub

    Here I have nothing:

    Code:
    Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        End Sub
    Backgroundworker finish:

    Code:
    Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
    
            If e.Error IsNot Nothing Then
                           MessageBox.Show(e.Error.Message)
    
    
            ElseIf e.Cancelled Then
                MessageBox.Show("Task cancelled!")
    
            Else
                MyProgressBar.Visible = False
                
                MsgBox("Copied completed", vbInformation, "Done")
                            Me.Enabled = True
            End If
    Am I placing that progressbar visible and not visible at right place? Or how else can I do this please?

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Backgroundworker and Progressbar

    This:
    vb.net Code:
    1. Me.Enabled = False
    is disabling the form. The Label is on the form so of course the Label is disabled.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Re: Backgroundworker and Progressbar

    Oh gosh!! I did not see that....

    Thank you very much sir!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width