MichelleLacy
asked on
BackgroundWorker
I have a form that load data from a database. While the form is loading I have a pop-up window that says please wait. I am trying to use the backgroundworker to have it run while the form is loading and disappear after it is done. How do I use the BackgroundWorker methods (DoWork, RunWorkerCompleted, ProgressChanged) to open a dialog that says "please wait while form is loading" and then automatically closes once the form has loaded.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I use the ToolStripProgressBar and a label to update the page as the long running process is running in my class.
I have a Win Form called frmActivation and the big process is in a class called cActivation.
So showing the relevant parts I have:
Source: http://discuss.joelonsoftware.com/default.asp?dotnet.12.563832.5
I have a Win Form called frmActivation and the big process is in a class called cActivation.
So showing the relevant parts I have:
Source: http://discuss.joelonsoftware.com/default.asp?dotnet.12.563832.5
Public Class frmActivation
'The class that has the long running process in it.
Private WithEvents _Activation As ADEActivationLib.AdvancedDigitalEngines.cActivation
Private _tspb As ToolStripProgressBar
' The start of the big process
Private Sub Submit()
...
_tspb = CType(CType(Me.ParentForm, MDIParent1).ToolStrip1.Items("ToolStripProgressBar1"), ToolStripProgressBar)
_tspb.Enabled = True
_tspb.Value = 10
Me.lblStatus.Text = "Please Wait, this may take a minute or two."
Me.lblStatus.Visible = True
Me.Refresh()
_Activation = New ....
End Sub
'An update method that gets called by cActivation at different steps in its processing.
'Notice the "Handles" part.
Private Sub StatusUpdate(ByVal Message As String) Handles _Activation.StatusChanged
Me.lblStatus.Text = Message
_tspb.Value = _tspb.Value + 10
Me.Refresh()
End Sub
End Class
'Then in cActivation at different steps I have the following calls:
RaiseEvent StatusChanged("Setting up Activation")
RaiseEvent StatusChanged("Getting License from WebService")
RaiseEvent StatusChanged("Geting Current keys if any")
RaiseEvent StatusChanged("Confirming License")
RaiseEvent StatusChanged("Evaluating / Saving License")
etc.
Hi,
set WorkerReportsProgress to true.
define the RunWorkerCompleted to a event handler, when this will be fired then close your window alert.
Good luck!
set WorkerReportsProgress to true.
define the RunWorkerCompleted to a event handler, when this will be fired then close your window alert.
Good luck!
http://www.c-sharpcorner.com/UploadFile/LivMic/BGWorker07032007000515AM/BGWorker.aspx