By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

Running long peace of codes in UI thread - problem with progress bar

P: n/a
Hello,

I'm programming an application based on CAB infrastructure in the
client side (c# .net 2005)

Since my application must be sequencally, i wrote all the code in the
UI thread.

my problem occurs when i try to show a progress bar. The screen
freezes. I know i'm not the first one to ask about it. but i'm looking
for advanced methods.

my limitations are:
1. i can't move my code from the UI thread to diffrent thread.
2. i must show progress bar (which actually moves)
3. i cannot use Application.doevents - it mess my application with
duplicate messages.

i tried using backgroundworker to bypass the problem without success.

i though maybe using animated gif, but i'm tring to avoid this option.

what can i do?

thanks,
Eran.

Aug 30 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
The advanced way would be to run it in a background thread. If you could
possibly get it working in a background worker then you can get it working
in a background thread. Perhaps if you give us a bit more code that we can
look at we can show you how to doit with a thread?

Cheers,

Greg

"esakal" <er*******@yahoo.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Hello,

I'm programming an application based on CAB infrastructure in the
client side (c# .net 2005)

Since my application must be sequencally, i wrote all the code in the
UI thread.

my problem occurs when i try to show a progress bar. The screen
freezes. I know i'm not the first one to ask about it. but i'm looking
for advanced methods.

my limitations are:
1. i can't move my code from the UI thread to diffrent thread.
2. i must show progress bar (which actually moves)
3. i cannot use Application.doevents - it mess my application with
duplicate messages.

i tried using backgroundworker to bypass the problem without success.

i though maybe using animated gif, but i'm tring to avoid this option.

what can i do?

thanks,
Eran.

Aug 30 '06 #2

P: n/a

esakal wrote:
Hello,

I'm programming an application based on CAB infrastructure in the
client side (c# .net 2005)

Since my application must be sequencally, i wrote all the code in the
UI thread.

my problem occurs when i try to show a progress bar. The screen
freezes. I know i'm not the first one to ask about it. but i'm looking
for advanced methods.

my limitations are:
1. i can't move my code from the UI thread to diffrent thread.
2. i must show progress bar (which actually moves)
3. i cannot use Application.doevents - it mess my application with
duplicate messages.

i tried using backgroundworker to bypass the problem without success.

i though maybe using animated gif, but i'm tring to avoid this option.

what can i do?
The cheap and nasty way to get things working is the
Application.DoEvents(). However, as you pointed out, this can result in
events you don't want processed, such as button clicks, being processed
at inappropriate places.

So, you need to do things like this:

public class CABForm : Form
{
...
this.Enabled = false; // Disable all controls on the form
... // Do long-running process, calling Application.DoEvents() from
time to time
this.Enabled = true; // Re-enable all controls on the form
...
}

It is only in this way that you can guarantee that the user can't mess
with the controls while you're working.

Incidentally, the solution for background threads is pretty-much the
same, and a background worker thread is the correct way to solve the
problem. The idea is the same:

1. Disable the entire form
2. Launch the background thread, have it call you back using Invoke()
when it's done.
3. In the callback method, re-enable the entire form

The background thread is the better way to do things because with
Application.DoEvents() you still end up with a (mostly) frozen
application, and the user can't move it, minimize it, etc while it's
working.

Aug 30 '06 #3

P: n/a
| 1. i can't move my code from the UI thread to diffrent thread.

Why? You said you where using a backgroundworker - that is another thread.
Please expand on this requirement.
--
William Stacey [MVP]

Aug 31 '06 #4

P: n/a
Thanks for the replies....

I can't really bring code since the application is very big (contains a
lot of codes.

I mentioned at the beginning that i'm using CAB infrastructure.

CAB encourages you to write your code in the main thread (UI thread).

Since most of the requests are sent to a server and proccessed there.
all the application has to do is to wait. i cannot even allow the user
to abort the action. meanwhile i would to show progress bar.

According to the architecture i mentioned, is it still important to use
diffrent thread?

Eran Sakal.

Aug 31 '06 #5

P: n/a

esakal wrote:
Thanks for the replies....

I can't really bring code since the application is very big (contains a
lot of codes.

I mentioned at the beginning that i'm using CAB infrastructure.

CAB encourages you to write your code in the main thread (UI thread).

Since most of the requests are sent to a server and proccessed there.
all the application has to do is to wait. i cannot even allow the user
to abort the action. meanwhile i would to show progress bar.

According to the architecture i mentioned, is it still important to use
diffrent thread?
Yes. If you don't use a background thread (or Application.DoEvents)
then you can't move the progress bar. If your user grabs your
application window and drags it, it may not even redraw (just stay
blank). In other words, your application will appear "frozen" until the
waiting is over.

If you use a background thread, you can still prevent the user from
doing things that he shouldn't be disabling controls and using the
form's Closing event to prevent him from closing the window. You can,
in effect, leave the UI thread live while preventing the user from
doing things you don't want him to be able to do.

Aug 31 '06 #6

P: n/a
Esakal,

In old samples from Microsoft will there is opened a non modal form for this
were you can place a running gif, showing that you are busy.

At the end of your process you close this form.

It is a very easy and cheap way to do.

Cor

"esakal" <er*******@yahoo.comschreef in bericht
news:11*********************@i3g2000cwc.googlegrou ps.com...
Hello,

I'm programming an application based on CAB infrastructure in the
client side (c# .net 2005)

Since my application must be sequencally, i wrote all the code in the
UI thread.

my problem occurs when i try to show a progress bar. The screen
freezes. I know i'm not the first one to ask about it. but i'm looking
for advanced methods.

my limitations are:
1. i can't move my code from the UI thread to diffrent thread.
2. i must show progress bar (which actually moves)
3. i cannot use Application.doevents - it mess my application with
duplicate messages.

i tried using backgroundworker to bypass the problem without success.

i though maybe using animated gif, but i'm tring to avoid this option.

what can i do?

thanks,
Eran.

Aug 31 '06 #7

P: n/a

"esakal" <er*******@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
| Thanks for the replies....
|
| I can't really bring code since the application is very big (contains a
| lot of codes.
|
| I mentioned at the beginning that i'm using CAB infrastructure.
|
| CAB encourages you to write your code in the main thread (UI thread).
|

Eek, why do they do this?

| Since most of the requests are sent to a server and proccessed there.
| all the application has to do is to wait. i cannot even allow the user
| to abort the action. meanwhile i would to show progress bar.
|

Does it mean that the application (the thread) is blocked waiting for the
server call to return?
If that's the case, there is nothing you can do, a thread that makes a
blocking call is obviously not able to do anything else than wait. Now you
mentioned DoEvents(), where are you calling this, if the remote server call
is blocking, DoEvents() will not serve you anything.

| According to the architecture i mentioned, is it still important to use
| diffrent thread?
|
| Eran Sakal.
|

You said you tried the BackgroundWorker (that means another thread) without
success, what were the issues?
As I said above, if the remote server call is blocking, the Background
worker thread is blocked and he cannot signal progress to the UI thread.
Could it be that this is your issue?
Willy.
Aug 31 '06 #8

P: n/a
well.

my problem is that i didn't choose this architecture. i have several
limitations and the main one is that i cannot move the logical code
from the main thread.

In order to bypass that limitation, i tried the following:

1. creating an other form which will show the progress bar (also tried
using anitmated gif in this form).

2. showing animated gif using browser thinking maybe its' content will
be host in an other thread.

since both of my ways failed. i have 2 questions:

1. is it optional to create two forms, each one on seperate thread? (i
will try doing so using backgroundworker when i will get home).

2. should i try to continue looking for solution or did i got to
deadend?

Many thanks.
Eran.

Aug 31 '06 #9

P: n/a
I needed something very similar. What I did is as follows.

1. Create an Activity form with a progress bar on it.
2. Create an activity class
3. In the class I have an Activity start property, when this is called
it creates a seperate background thread that calls a function. This
function creates an instance of another class (which is running in the
new thread, it then create an instance of the activity form and handles
updating of the progress bar automatically. This is the way I did it, I
cannot say if this is the best or correct way, but this does work for
me.

Code Below

'************************************************* **********
' Author: Adelio Stevanato
' Activity form, that shows that something is happening.
' All this code is to allow me to show a stateless actvity
' form. in this case a progress bat that cycles 1-100
' then restarts at 1
' the form is NOT called directly but from a class
' called clsActivity
' This handles all the thread stuff
'************************************************* **********

'Friend - Activity form, not accessable elsewhere
Friend Class frmActive
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If

MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lblInfo As System.Windows.Forms.Label
Friend WithEvents BackgroundWorker1 As
System.ComponentModel.BackgroundWorker
Friend WithEvents PBar As System.Windows.Forms.ProgressBar

<System.Diagnostics.DebuggerStepThrough()Private Sub
InitializeComponent()
Me.lblInfo = New System.Windows.Forms.Label
Me.PBar = New System.Windows.Forms.ProgressBar
Me.BackgroundWorker1 = New
System.ComponentModel.BackgroundWorker
Me.SuspendLayout()
'
'lblInfo
'
Me.lblInfo.Anchor =
CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
Me.lblInfo.BackColor = System.Drawing.SystemColors.Window
Me.lblInfo.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D
Me.lblInfo.Location = New System.Drawing.Point(0, 0)
Me.lblInfo.Name = "lblInfo"
Me.lblInfo.Size = New System.Drawing.Size(320, 39)
Me.lblInfo.TabIndex = 1
Me.lblInfo.Text = "Processing...."
Me.lblInfo.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter
'
'PBar
'
Me.PBar.Dock = System.Windows.Forms.DockStyle.Bottom
Me.PBar.Location = New System.Drawing.Point(0, 36)
Me.PBar.Name = "PBar"
Me.PBar.Size = New System.Drawing.Size(320, 20)
Me.PBar.Step = 1
Me.PBar.TabIndex = 2
'
'BackgroundWorker1
'
'
'frmActive
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(320, 56)
Me.ControlBox = False
Me.Controls.Add(Me.PBar)
Me.Controls.Add(Me.lblInfo)
Me.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedToolWind ow
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmActive"
Me.ShowInTaskbar = False
Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide
Me.StartPosition =
System.Windows.Forms.FormStartPosition.CenterParen t
Me.TopMost = True
Me.Controls.SetChildIndex(Me.lblInfo, 0)
Me.Controls.SetChildIndex(Me.PBar, 0)
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
#End Region

Dim mstrInfo As String
Dim m_Val As Integer = 0
Dim m_owner As Form

Dim m_FormLocation As clsActivity.PositionLocation =
clsActivity.PositionLocation.Centre

Public Sub New(ByVal message As String)
Me.New()
mstrInfo = message
Info = mstrInfo
End Sub

Public Sub New(ByVal message As String, ByVal Owner As Form)
Me.New()
mstrInfo = message
Info = mstrInfo
m_owner = Owner
End Sub

Public Property FormLocation() As clsActivity.PositionLocation
Get
Return m_FormLocation
End Get
Set(ByVal Value As clsActivity.PositionLocation)
If m_FormLocation <Value Then
m_FormLocation = Value
If Me.Visible = True Then
Call PositionForm()
End If
End If
End Set
End Property

Public Property Info() As String
Get
Return mstrInfo
End Get
Set(ByVal Value As String)
mstrInfo = Value
lblInfo.Text = mstrInfo
Me.Refresh()
End Set
End Property

Public Sub StartActivity()
lblInfo.Text = mstrInfo
If Me.Visible = False Then
Me.Show()
End If
Call PositionForm()
Me.BringToFront()
m_Val = 0
End Sub

Public Shadows ReadOnly Property Owner() As Form
Get
Return m_owner
End Get
End Property

Private Sub PositionForm()

If m_FormLocation = clsActivity.PositionLocation.Centre Then
If m_owner Is Nothing Then
CentreForm(Me)
Else
If m_owner.MdiParent Is Nothing Then
Me.Location = New Point(CInt((m_owner.Left +
(m_owner.Width / 2))) - CInt(Me.Width / 2), m_owner.Top +
CInt(m_owner.Height / 2) - CInt(Me.Height / 2))
Else
If Not m_owner.MdiParent Is Nothing Then
Me.Location = New Point((m_owner.Left +
m_owner.MdiParent.Left + CInt(m_owner.Width / 2)) - CInt(Me.Width / 2),
m_owner.Top + m_owner.MdiParent.Top + CInt(m_owner.Height / 2) -
CInt(Me.Height / 2))
Else
CentreForm(Me)
End If
End If
End If
Else
If m_FormLocation = clsActivity.PositionLocation.BottomRight
Then
If m_owner Is Nothing OrElse m_owner.MdiParent Is
Nothing Then
Me.Left = Screen.PrimaryScreen.Bounds.Width -
Me.Width
Me.Top = Screen.PrimaryScreen.Bounds.Height -
Me.Height
Else
Me.Left = m_owner.MdiParent.Right - (Me.Width + 8)
Me.Top = m_owner.MdiParent.Bottom - (Me.Height + 31)
End If
Else
If m_owner Is Nothing OrElse m_owner.MdiParent Is
Nothing Then
Me.Left = Screen.PrimaryScreen.Bounds.Left + 8
Me.Top = Screen.PrimaryScreen.Bounds.Height -
Me.Height
Else
Me.Left = m_owner.MdiParent.Left + 6
Me.Top = m_owner.MdiParent.Bottom - (Me.Height + 31)
End If
End If
End If

Me.Refresh()
End Sub

Private Sub EndActivity(ByVal CloseForm As Boolean)
m_Val = 0
If CloseForm Then
Me.Close()
End If
End Sub

Public Sub EndActivity()
Me.Close()
End Sub

Public Sub DoStep()
Call DoStep(-1)
End Sub

Public Sub DoStep(ByVal Value As Integer)
If Value 0 AndAlso Value <= 100 Then
m_Val = Value
Else
m_Val += 1
If m_Val 100 Then
m_Val = 1
End If
End If

PBar.Value = m_Val
End Sub
End Class

' PUBLIC Calling Class
Public Class clsActivity
Implements IDisposable

Public Enum PositionLocation
Centre = 0
BottomRight = 1
BottomLeft = 2
End Enum

Private Enum ActivityMode
Unknown = 0
StartActivity = 1
EndActivity = 2
PauseActivity = 3
ResumeActivity = 4
End Enum

Public Enum ActivityStatus
Uninitalised = 0
Running = 1
Ended = 2
Pauses = 3
End Enum

Private HasStarted As Boolean = False
Private m_Th As System.Threading.Thread
Private m_mode As ActivityMode
Private m_CurrentStatus As ActivityStatus =
ActivityStatus.Uninitalised
Private m_modeChanged As Boolean = False
Private m_MaxDisplayTimeSecs As Long = (10 * 60) 'Max time to
display Activity display (3 mins)
Private m_StartTime As Date
Private m_ThreadInterval As Integer = 10
Private m_Info As String = "Processing..."
Private m_Owner As Form
Dim m_FormLocation As PositionLocation = PositionLocation.Centre

Public Sub New()
End Sub

Public Sub New(ByVal Info As String)
m_Info = Info
End Sub

Public Sub New(ByVal Info As String, ByVal Owner As
System.Windows.Forms.Form)
m_Info = Info
m_Owner = Owner
End Sub

'Specifies the interval in Milliseconds between updates
Public Property UpdateInterval() As Integer
Get
Return m_ThreadInterval
End Get
Set(ByVal Value As Integer)
If Value 0 AndAlso Value < 1000 Then
m_ThreadInterval = Value
End If
End Set
End Property

Public Property FormLocation() As PositionLocation
Get
Return m_FormLocation
End Get
Set(ByVal Value As PositionLocation)
If m_FormLocation <Value Then
m_FormLocation = Value
End If
End Set
End Property

'Specifies the Max amount of time to have the activity runnimg,
Default to 3 minutes
Public Property MaxDisplayTimeSecs() As Long
Get
Return m_MaxDisplayTimeSecs
End Get
Set(ByVal Value As Long)
m_MaxDisplayTimeSecs = Value
End Set
End Property

Public ReadOnly Property CurrentStatus() As ActivityStatus
Get
Return m_CurrentStatus
End Get
End Property

Public ReadOnly Property Owner() As Form
Get
Return m_Owner
End Get
End Property

Public Property Info() As String
Get
Return m_Info
End Get
Set(ByVal Value As String)
m_Info = Value
End Set
End Property

Public Sub Startup()
If Not HasStarted Then
HasStarted = True
m_mode = ActivityMode.StartActivity
m_modeChanged = True
m_Th = New System.Threading.Thread(AddressOf DoActivity)
m_Th.IsBackground = True
m_Th.Start()
End If
End Sub

<System.ComponentModel.Description("End the activity display")_
Public Sub EndActivity()
Mode = ActivityMode.EndActivity
End Sub

<System.ComponentModel.Description("Pause the activity display")_
Public Sub PauseActivity()
Mode = ActivityMode.PauseActivity
End Sub

<System.ComponentModel.Description("Resume the activity display")_
Public Sub ResumeActivity()
Mode = ActivityMode.ResumeActivity
End Sub

Private Property Mode() As ActivityMode
Get
Return m_mode
End Get
Set(ByVal Value As ActivityMode)
m_mode = Value
m_modeChanged = True

If Value = ActivityMode.EndActivity Then

System.Threading.Thread.Sleep(20)

If Not m_Th Is Nothing Then
System.Threading.Thread.Sleep(75)
Dim tm As Date = Now

While Not m_Th Is Nothing
System.Threading.Thread.Sleep(25)
If m_Th.ThreadState And
(Threading.ThreadState.Stopped) = 0 OrElse m_Th.ThreadState And
(Threading.ThreadState.Aborted) = 0 Then
m_Th = Nothing
Else
If DateDiff(DateInterval.Second, tm, Now) >
0 Then
m_Th.Abort()
m_Th = Nothing
End If
End If
End While
End If
End If
End Set
End Property

'Class run in separate thread
Private Sub DoActivity()

#If DEBUG Then
Try
#End If

Dim Act As Activity

While True
'This code checks if the form has been disposed, if it
has DO NOT DO ANYTHING
If Not Act Is Nothing AndAlso
Act.Activityform.IsDisposed = True Then
m_CurrentStatus = ActivityStatus.Ended
Exit While
End If

'IF the thread has been aborted then Exit from the loop
If System.Threading.Thread.CurrentThread.ThreadState And
(Threading.ThreadState.Aborted) = 0 Then
pos = "1a"
m_CurrentStatus = ActivityStatus.Ended
Exit While
End If

'
'If activity form active for too long then Stop Activity
'
If m_CurrentStatus = ActivityStatus.Running AndAlso
DateDiff(DateInterval.Second, m_StartTime, Now) m_MaxDisplayTimeSecs
Then
m_mode = ActivityMode.EndActivity
m_modeChanged = True
If Not Act Is Nothing Then
Act.EndActivity()
End If
m_CurrentStatus = ActivityStatus.Ended
#If DEBUG Then
Throw New Exception("clsActivity::DoActivity :-
Timeout of activity status, max= " & m_MaxDisplayTimeSecs & " Seconds")
#End If
End If

'IF the thread has been aborted then Exit from the loop
If System.Threading.Thread.CurrentThread.ThreadState And
(Threading.ThreadState.Aborted) = 0 Then
m_CurrentStatus = ActivityStatus.Ended
Exit While
End If

' This codee only called if the mode as changed
If m_modeChanged = True Then
'I want to start
If m_CurrentStatus <ActivityStatus.Running AndAlso
Mode = ActivityMode.StartActivity Then
If Act Is Nothing Then
Act = New Activity(Info, Owner)
Act.Info = Info
Act.FormLocation = m_FormLocation
m_CurrentStatus = ActivityStatus.Running
Act.StartActivity()
m_StartTime = Now
End If

'I want to end
ElseIf m_mode = ActivityMode.EndActivity Then
If Not Act Is Nothing Then
Act.EndActivity()
End If
m_CurrentStatus = ActivityStatus.Ended
Exit While

'I want to pause
ElseIf m_CurrentStatus = ActivityStatus.Running
AndAlso m_mode = ActivityMode.PauseActivity Then
If Not Act Is Nothing Then
Act.PauseActivity()
m_CurrentStatus = ActivityStatus.Pauses
End If

'Iwant to resume a pause
ElseIf m_CurrentStatus = ActivityStatus.Pauses
AndAlso m_mode = ActivityMode.ResumeActivity Then
If Not Act Is Nothing Then
Act.ResumeActivity()
m_CurrentStatus = ActivityStatus.Running
End If
End If
m_modeChanged = False
End If

'IF the thread has been aborted then Exit from the loop
If System.Threading.Thread.CurrentThread.ThreadState And
(Threading.ThreadState.Aborted) = 0 Then
m_CurrentStatus = ActivityStatus.Ended
Exit While
End If

'If running then refresh form and do another step
If m_CurrentStatus <ActivityStatus.Ended AndAlso
m_CurrentStatus <ActivityStatus.Uninitalised Then
If Not Act Is Nothing Then
If Act.Info <m_Info Then
Act.Info = m_Info
End If
Act.FormLocation = m_FormLocation
Act.DoStep()
End If
End If

'IF the thread has been aborted then Exit from the loop
If Not
(System.Threading.Thread.CurrentThread.ThreadState And
(Threading.ThreadState.Aborted) = 0) Then
'Sleep for a little bit, this controls how quickly
the progress bar on the activity form steps
System.Threading.Thread.Sleep(m_ThreadInterval)
Else
m_CurrentStatus = ActivityStatus.Ended
Exit While
End If

'This code checks if the form has been disposed, if it
has DO NOT DO ANYTHING
If Not Act Is Nothing AndAlso
Act.Activityform.IsDisposed = True Then
m_CurrentStatus = ActivityStatus.Ended
Exit While
End If

Application.DoEvents()

'IF the thread has been aborted then Exit from the loop
If System.Threading.Thread.CurrentThread.ThreadState And
(Threading.ThreadState.Aborted) = 0 Then
m_CurrentStatus = ActivityStatus.Ended
Exit While
End If

End While

#If DEBUG Then
Catch ex As Exception
MsgBox(ex.Message)
End Try
#End If

End Sub

Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not m_Th Is Nothing Then
m_mode = ActivityMode.EndActivity
End If
End If
End Sub

Protected Overrides Sub Finalize()
m_mode = ActivityMode.EndActivity
m_CurrentStatus = ActivityStatus.Ended
MyBase.Finalize()
End Sub
End Class

' This is a Friend class as well.
Friend Class Activity
Private m_ActivityForm As frmActive
Private m_Pause As Boolean = False
Private m_started As Boolean = False
Private m_Owner As Form
Private m_formLocation As clsActivity.PositionLocation

<System.ComponentModel.Description("Default Constructor")_
Public Sub New()
m_ActivityForm = New frmActive
End Sub

<System.ComponentModel.Description("Default Constructor with an
initial activity message")_
Public Sub New(ByVal Info As String)
m_ActivityForm = New frmActive(Info)
End Sub

<System.ComponentModel.Description("Default Constructor with an
initial activity message")_
Public Sub New(ByVal Info As String, ByVal Owner As Form)
m_Owner = Owner
m_ActivityForm = New frmActive(Info, Owner)
End Sub

<System.ComponentModel.Description("The Activity Form")_
Public ReadOnly Property Activityform() As frmActive
Get
Return m_ActivityForm
End Get
End Property

Public Property FormLocation() As clsActivity.PositionLocation
Get
Return m_FormLocation
End Get
Set(ByVal Value As clsActivity.PositionLocation)
If m_FormLocation <Value Then
m_formLocation = Value
If Not m_ActivityForm Is Nothing Then
m_ActivityForm.FormLocation = m_formLocation
End If
End If
End Set
End Property

<System.ComponentModel.Description("Change the current activity
mesage being displayed")_
Public Property Info() As String
Get
Return m_ActivityForm.Info
End Get
Set(ByVal Value As String)
m_ActivityForm.Info = Value
End Set
End Property

Public Sub DoStep()
If m_started = True AndAlso m_Pause = False Then
m_ActivityForm.DoStep()
End If
End Sub

<System.ComponentModel.Description("The Activity Form")_
Public Sub StartActivity(ByVal Info As String)
m_started = True
m_Pause = False
Call m_ActivityForm.StartActivity()
End Sub

<System.ComponentModel.Description("Start the activity display")_
Public Sub StartActivity()
m_started = True
m_Pause = False
Call m_ActivityForm.StartActivity()
End Sub

<System.ComponentModel.Description("End the activity display")_
Public Sub EndActivity()
m_started = False
m_Pause = False
Call m_ActivityForm.EndActivity()
m_ActivityForm = Nothing
m_ActivityForm = New frmActive
End Sub

<System.ComponentModel.Description("Pause the activity display")_
Public Sub PauseActivity()
m_Pause = True
End Sub

<System.ComponentModel.Description("Resume the activity display")_
Public Sub ResumeActivity()
m_Pause = False
End Sub

Protected Overrides Sub Finalize()
If Not m_ActivityForm Is Nothing Then
m_ActivityForm.EndActivity()
m_ActivityForm = Nothing
End If
MyBase.Finalize()
End Sub
End Class
*** Sent via Developersdex http://www.developersdex.com ***
Sep 13 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.