Question ProgressBar ProgressBarStyle.Marquee not working

gchq

Well-known member
Joined
Dec 14, 2007
Messages
168
Programming Experience
10+
Hi there

I have the following sub that displays the progress (the Animation speed is 50 - but I've tried with other values)

VB.NET:
Public Sub MainTabsLoad(ByVal Message As String)
        TabsStatuslabel.Text = Message
        TabsProgressBar.Style = ProgressBarStyle.Marquee
        TabsProgressBar.MarqueeAnimationSpeed = My.Settings.MarqueeAnimSpeed
        Form1.Cursor = Cursors.WaitCursor
        Form1.Refresh()
    End Sub

and this when it completes

VB.NET:
 Public Sub MainTabsLoaded(ByVal Message As String)
        TabsStatuslabel.Text = Message
        TabsProgressBar.Style = ProgressBarStyle.Blocks
        TabsProgressBar.Maximum = 1
        TabsProgressBar.Value = TabsProgressBar.Minimum
        Form1.Cursor = Cursors.Default
        Form1.Refresh()
    End Sub

In XP it shows 4 blocks, then stops - in Win 7 it just plain doesn't work.

Application.RenderWithVisualStyles is set to true (and tested)

I should mention that the control is created dynamically and placed on a dynamically created TabPage that in turn is added to the main tab control that is on the static form (Form1) that is refreshed - but I do believe that 'Refresh' should ripple though to all sub controls?

Any ideas?

Thanks
 
If you're displaying a marquee progress bar then presumably you're doing something else at the same time. My guess is that you're performing that other task on the UI thread, so the UI thread is too busy to update the progress bar. If that is the case, you need to shift your other task to a secondary thread, so that the UI thread is free to look after the UI.
 
Multi-threading

Got some of the basics understood

VB.NET:
Imports System.ComponentModel

 Public BW1 As BackgroundWorker


Code to run in background
VB.NET:
 Private Sub RunNominalCodeReportToPDF_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
'Run the code in the background

Sub from the click button event
VB.NET:
Public Sub RunNominalCodeReportToPDF(ByVal sender As Object, ByVal e As EventArgs)
 BW1 = New BackgroundWorker
        AddHandler BW1.DoWork, AddressOf RunNominalCodeReportToPDF_DoWork
        BW1.RunWorkerAsync()

But how do I fire the background event?
 
Have got a little further, but still can't get the background process to work.

This is the form that loads with the button to run the event
VB.NET:
 Public Sub LoadGeneralLedgerReportTab()
        GeneralLedgerReportTab.Controls.Clear()
        Dim vpanel As New Panel
        With vpanel
            .Dock = DockStyle.Fill
            .AutoScroll = True
        End With

        Dim GLStartDateLB As New Label
        With GLStartDateLB
            .Text = "Start Date"
            .Size = New Point(100, 20)
            .Location = New Point(10, 10)
        End With
        vpanel.Controls.Add(GLStartDateLB)

        Dim GLStartDateTB As New TextBox
        With GLStartDateTB
            .Name = "GLStartDateTB"
            .Size = New Point(100, 20)
            .Location = New Point(115, 10)
            .Text = ReturnLocalDateFormat(Form1.AnnualData.Rows(0)("Year_Start"))
        End With
        AddHandler GLStartDateTB.GotFocus, AddressOf GLReportEnableCalendar
        AddHandler GLStartDateTB.LostFocus, AddressOf GLReportDisableCalendar
        vpanel.Controls.Add(GLStartDateTB)

        Dim GLEndDateLB As New Label
        With GLEndDateLB
            .Text = "End Date"
            .Size = New Point(100, 20)
            .Location = New Point(10, 35)
        End With
        vpanel.Controls.Add(GLEndDateLB)

        Dim vStartDate As Date = DateAdd("D", -1.0 * DatePart("D", Today) + 1, Today)


        Dim GLEndDateTB As New TextBox
        With GLEndDateTB
            .Name = "GLEndDateTB"
            .Size = New Point(100, 20)
            .Location = New Point(115, 35)
            .Text = DateAdd(DateInterval.Day, -1, vStartDate)
        End With
        AddHandler GLEndDateTB.GotFocus, AddressOf GLReportEnableCalendar
        AddHandler GLEndDateTB.LostFocus, AddressOf GLReportDisableCalendar
        vpanel.Controls.Add(GLEndDateTB)

        Dim vToolStrip As New ToolStrip
        With vToolStrip
            .ImageScalingSize = New Point(32, 32)
            .Name = "GLReportToolStrip"
        End With

        Dim vPDF As New ToolStripButton
        With vPDF
            .Image = My.Resources.PDF
            .ToolTipText = "Run report"

        End With
        AddHandler vPDF.Click, AddressOf RunNominalCodeReportToPDF
        vToolStrip.Items.Add(vPDF)

        Dim vCalendar As New ToolStripButton
        With vCalendar
            .Name = "GLCalendar"
            .Enabled = False
            .Image = My.Resources.Calendar
            .ToolTipText = "Insert Date"
        End With
        AddHandler vCalendar.Click, AddressOf GLReportInsertDate
        vToolStrip.Items.Add(vCalendar)

        TabsStatusStrip = New StatusStrip
        TabsProgressBar = New ToolStripProgressBar
        TabsStatuslabel = New ToolStripStatusLabel
        TabsStatusStrip.Items.Add(TabsProgressBar)
        TabsStatusStrip.Items.Add(TabsStatuslabel)


        GeneralLedgerReportTab.Controls.Add(vpanel)
        GeneralLedgerReportTab.Controls.Add(vToolStrip)
        GeneralLedgerReportTab.Controls.Add(TabsStatusStrip)

        BW1 = New BackgroundWorker
        AddHandler BW1.DoWork, AddressOf RunNominalCodeReportToPDF_DoWork
        AddHandler BW1.RunWorkerCompleted, AddressOf RunNominalCodeReportToPDF_WorkCompleted

    End Sub

.. and clicking the button runs this

VB.NET:
Public Sub RunNominalCodeReportToPDF(ByVal sender As Object, ByVal e As EventArgs)
        MainTabsLoad("Running General Ledger Report... Please wait...")

        Dim StartDateTB As TextBox = RFC(Form1, "GLStartDateTB")
        Dim EndDateTB As TextBox = RFC(Form1, "GLEndDateTB")
        If Not IsDate(StartDateTB.Text) Then
            AppBox.Show("The Start Date is not a valid date!", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        If Not IsDate(EndDateTB.Text) Then
            AppBox.Show("The End Date is not a valid date!", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        BW1.RunWorkerAsync()
    End Sub


and these are the BackgroundWorker events

VB.NET:
Public Sub RunNominalCodeReportToPDF_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)

        Dim StartDateTB As TextBox = RFC(Form1, "GLStartDateTB")
        Dim EndDateTB As TextBox = RFC(Form1, "GLEndDateTB")

        Dim vservice As New ServiceReference1.Service1Client
        Dim vDS As DataSet = vservice.ReturnTotalNominalByDate(StartDateTB.Text, EndDateTB.Text, Form1.vCurrentHOA)
        Dim vDT As DataTable = vDS.Tables(0)
        If vDT.Rows.Count = 0 Then
            AppBox.Show("There are no records to display for the selected timeframe!", MessageBoxButtons.OK, MessageBoxIcon.Information)
            vservice.Close()
            vservice = Nothing
            Exit Sub
        End If
        If vDT.Rows(0)("Nominal_Code") = 0 Then
            vservice.Close()
            vservice = Nothing
            AppBox.Show("There was an error returning the General Ledger Data!", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If

        vservice.Close()
        vservice = Nothing

        Dim vOutput As String = RunNominalCodeReport(StartDateTB.Text, EndDateTB.Text)
        If System.IO.File.Exists(vOutput) Then
            Dim P As New Process
            P.StartInfo.FileName = vOutput
            P.StartInfo.Verb = "Open"
            P.Start()
        End If
    End Sub

    Public Sub RunNominalCodeReportToPDF_WorkCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
        MainTabsLoaded("")
        'BW1.Dispose()
        'BW1 = Nothing
    End Sub

It displays the running text and removes it via the Workcompleted event, but the actual 'work' is not carried out!

Any ideas?
 
Sussed out what is going on. It has no problem downloading the data, but the final part of the operation consists of a whole raft of different functions that would have to be run on the background thread.

If I set the background thread to sleep the progress bar works as it should...

Thanks for pointing me in the right direction.
 
Back
Top