Avatar of blitzzy
blitzzy

asked on 

VB.NET 2005 - Status label not updating with progress bar

I am writing a program in VB.NET 2005 that contains a StatusStrip, progress bar, and status label. Each time a file is copied, the progress bar increments and the status label should say "Copying fax # xx of xx." The problem is that the progress bar works fine, but the status label is not displayed until the progress bar finishes. When I stepped through the code, I see that the status label is updated correctly; it just isn't displayed until AFTER the progress bar. I would like for the status label to be displayed and updated at the same time that the progress bar is updated. Does this require threading? If so, can someone please show me how (with code) because I have no clue when it comes to threading. Thanks!

[b]Here's my code:[/b]
    Private Sub mnu_ReceiveFaxOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_ReceiveFaxOn.Click
        If mnu_ReceiveFaxOn.Checked Then
            Exit Sub
        Else
            mnu_ReceiveFaxOn.Checked = True
            mnu_ReceiveFaxOff.Checked = False
            sb_Status.Visible = True
            pbar_FaxStatus.Value = 0
            sbl_FaxStatus.Text = ""
            GetNewFaxes()
        End If
    End Sub

    Private Sub GetNewFaxes()
        Dim ClmFaxes As New DataTable
        Dim BatchNumber As Long
        Dim BatchName As String
        Dim TotalPages As Integer
        Dim SourceFile As String
        Dim DestFile As String
        Dim FaxCounter As Integer
        Dim RecordCount As Integer
        Dim PageCount As Integer

        Try
            GetClmFaxes(m_EmployeeID)
            ClmFaxes = LoadClmFaxes()

            RecordCount = ClmFaxes.Rows.Count

            For FaxCounter = 1 To RecordCount
[b]                sbl_FaxStatus.Text = "Copying fax # " & FaxCounter & " of " & RecordCount[/b]

                BatchNumber = ClmFaxes.Rows(FaxCounter - 1).Item("BaseID")
                BatchName = BatchNumber.ToString("00000000")
                TotalPages = ClmFaxes.Rows(FaxCounter - 1).Item("NumPages")

                For PageCount = 1 To TotalPages
                    SourceFile = My.Settings.ClmFaxFromPath & "\" & BatchName & "." & PageCount.ToString("000")
                    DestFile = My.Settings.ClmFaxTempPath & "\" & BatchName & "." & PageCount.ToString("000")

                    My.Computer.FileSystem.CopyFile(SourceFile, DestFile)
                Next

[b]                pbar_FaxStatus.Increment(10)[/b]
            Next

            Windows.Forms.Cursor.Current = Cursors.Default
        Catch ex As System.Exception
            My.Application.Log.WriteException(ex)
        End Try
    End Sub
.NET ProgrammingEditors IDEs

Avatar of undefined
Last Comment
Mike Tomlinson
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of blitzzy
blitzzy

ASKER

Thanks so much! It works great with the Application.DoEvents(). This wouldn't affect anything else in the application, would it?
It just depends HOW you're application was written.  From what I can see it won't affect anything...

You have to be careful that GUI events don't get fired again when the user clicks on them since Application.DoEvents() would allow them to be processed.  You can avoid that type of problem by disabling buttons, etc... until your loops are done...then enabling them again.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo