Modifying StatusBusy ProblemModifying StatusBusy Problem
Old forum URL: forums.lhotka.net/forums/t/3729.aspx
eslater posted on Tuesday, October 16, 2007
I am trying to modify StatusBusy to show a user control on the form that is using it but the control never appears. My StatusBusy class is as follows:
Public
Class StatusBusy
Implements IDisposable
Private mOldStatus As String
Private mOldCursor As Cursor
Private mWait As WaitForm
Private mForm As System.Windows.Forms.Form
Public Sub New(ByVal statusText As String, ByVal Form As System.Windows.Forms.Form)
mForm = Form
mOldStatus = frmMain.StatusLabel.Text
frmMain.StatusLabel.Text = statusText
mOldCursor = frmMain.Cursor
frmMain.Cursor = Cursors.WaitCursor
Dim mWait As New WaitForm(statusText)
mWait.Top = (mForm.Size.Height - mWait.Height) / 2
mWait.Left = (mMain.Size.Width - mWait.Width) / 2
mWait.BringToFront()
mForm.Controls.Add(mWait)
End Sub
Private disposedValue As Boolean = False ' To detect redundant calls
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
frmMain.StatusLabel.Text = mOldStatus
frmMain.Cursor = mOldCursor
mForm.Controls.Remove(mWait)
End If
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
End
Class
And I am calling it using code similar to the following:
Using busy As New StatusBusy("Loading Customer List...", Me)
'Doing some stuff here
End Using
Is anyone able to point me in the right direction?
eslater replied on Tuesday, October 16, 2007
Maybe I should point out I am not running an MDI app but none of the windows will have multiple instances.juddaman replied on Wednesday, October 17, 2007
In the Status property after setting the lablels text, refresh the label parent control, the status strip. Like so:
set
{
if (lblStatus.Text != value)
{
lblStatus.Text =
value;
statusStrip1.Refresh();
}
}
HTH
ajj3085 replied on Wednesday, October 17, 2007
Are performaing a long running operation? If so, you may want to use a Background worker component. The problem with the status busy approach is that it may never update, because the code immediately after is intensive and the message pump doesn't get processed until after all the code completes... which includes disposing of the status busy.
rexhxiao replied on Friday, October 19, 2007
public string StatusLabel
{
get { return _statusLabel.Text; }
set { _statusLabel.Text = value; Application.DoEvents(); }
}
ok?
I use it!
ajj3085 replied on Friday, October 19, 2007
Application.DoEvents is kind of a bad hack. It can cause some unpredictable problems. If you see yourself using it, I think you should consider the BackgroundWorker component instead. You shouldn't really be doing any "heavy lifting" in your UI thread if you can avoid it. The solution above will still cause the windows to detect your application as Not Responding for any long running process.
Copyright (c) Marimer LLC