Solved

Update Modal Dialog Progress Bar using Background Worker in VB.Net

Posted on 2012-03-21
2
2,448 Views
Last Modified: 2012-03-21
I promise I've looked for hours on a clear and concise VB.Net version of doing this. I can only piece together little bits and not the whole picture.

I have a parent form and a dialog pop up. I want to pop the dialog window, which contains a progress bar, and update the progress bar from the parent form as specific tasks are completed on the parent form.  That's it. I found an example that Idle_mind gave here, but it's c#, and it's not communicating to the modal dialog.

Help?

-MJC
0
Comment
Question by:Rainverse
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 37748669
Here's one way...by passing a reference to the BackgroundWorker() into the Progress Form:
Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = False
        Dim progress As New frmProgress(Me.BackgroundWorker1)
        progress.ShowDialog()
        Button1.Enabled = True
        MessageBox.Show("Done!")
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        For i As Integer = 1 To 100
            System.Threading.Thread.Sleep(100)
            BackgroundWorker1.ReportProgress(i)
        Next
    End Sub

End Class

Open in new window


Public Class frmProgress

    Private WithEvents _BGW As System.ComponentModel.BackgroundWorker

    Public Sub New(ByVal BGW As System.ComponentModel.BackgroundWorker)
        _BGW = BGW
        InitializeComponent()
    End Sub

    Private Sub frmProgress_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
        If Not IsNothing(_BGW) Then
            _BGW.RunWorkerAsync()
        End If
    End Sub

    Private Sub _BGW_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles _BGW.ProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
    End Sub

    Private Sub _BGW_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles _BGW.RunWorkerCompleted
        Me.Close()
    End Sub

End Class

Open in new window

0
 
LVL 5

Author Closing Comment

by:Rainverse
ID: 37748850
I was hoping you'd answer. Works great! Thanks!

-MJC
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question