Solved

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

Posted on 2012-03-21
2
2,504 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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