473,749 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with threading...

Using VS 2003, .NET:
I developed a windows application that performs several actions based on an
input file. The application displays a progress bar as each action executes.
Based on new requirements, this application needs to be able to shell off
other processes and wait while in the mean time displaying a progress bar of
the process's. I am using the System.Disgnost ics.Process class to "start"
and "waitForExi t" of these processes... I thought the best way to show status
was to kick off a separate thread that increments a progress bar on my GUI
while the processes's hasExited value is false... unfortunately this is not
working well for me. As I step through the code, everything looks good until
line 11 below executes... after executing this line nothing happens and the
application just hangs. Being a novice to threads, I wasn't sure if my
application of thread was appropriate in this instance (regardless I wanted
to try and make it work as a learning exercise). So, Is my application of a
separate thread appropriate? Should it be implemented differently, etc? Any
idea why the application just hangs after line 11?

Thanks for your attention to this, Charles:
1 Public Class frmMain
2 '....snip...
3 Private oProcess As System.Diagnost ics.Process
4 '....snip...
5 Friend WithEvents pgAction As System.Windows. Forms.ProgressB ar
6 '....snip...
7 Public Sub New()
8 MyBase.New()
9 'This call is required by the Windows Form Designer.
10 InitializeCompo nent()
11 'Add any initialization after the InitializeCompo nent() call
13 Me.MyMain()
14 End Sub
15 '....snip...
16 Private Sub IncrementAction Progress()
17 While Not oProcess.HasExi ted 'HACK start with a the progress bar
moving up 2 steps / second
18 If Me.pgAction.Val ue = 100 Then Me.pgAction.Val ue = 0 'Keep
going till thread is aborted...
19 Me.pgAction.Inc rement(1) 'declaration not shown...
20 System.Threadin g.Thread.Curren tThread.Sleep(5 00)
21 End While
22 End Sub
23 '....snip...
24 Private Sub MyMain
25 oProcess = New System.Diagnost ics.Process
26 Try
27 oProcess.StartI nfo.FileName = Process
28 oProcess.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal
29 oProcess.Start( )
30 Dim t As System.Threadin g.Thread
31 t = New System.Threadin g.Thread(Addres sOf
Me.IncrementAct ionProgress)
32 t.Start()
33 oProcess.WaitFo rExit()
34 t.Abort()
35 Me.pgAction.Val ue = Me.pgAction.Max imum 'Ensure that
progress bar goes to max...
36 Catch ex As Exception
37 Msgbox "Error: " & Err.Message 'TODO handle error
gracefully...
38 End Try
39 End Sub
Apr 18 '06 #1
6 1899
Hi,

If you want to use a progressbar, than you need to know

The Start
The in advance measured time or totalsteps that will be involved
The steps.

You know only the Start so your program makes in my opinion not much sense.

Cor
"hz****@nopost. com" <hz************ *@discussions.m icrosoft.com> schreef in
bericht news:E2******** *************** ***********@mic rosoft.com...
Using VS 2003, .NET:
I developed a windows application that performs several actions based on
an
input file. The application displays a progress bar as each action
executes.
Based on new requirements, this application needs to be able to shell off
other processes and wait while in the mean time displaying a progress bar
of
the process's. I am using the System.Disgnost ics.Process class to "start"
and "waitForExi t" of these processes... I thought the best way to show
status
was to kick off a separate thread that increments a progress bar on my GUI
while the processes's hasExited value is false... unfortunately this is
not
working well for me. As I step through the code, everything looks good
until
line 11 below executes... after executing this line nothing happens and
the
application just hangs. Being a novice to threads, I wasn't sure if my
application of thread was appropriate in this instance (regardless I
wanted
to try and make it work as a learning exercise). So, Is my application of
a
separate thread appropriate? Should it be implemented differently, etc?
Any
idea why the application just hangs after line 11?

Thanks for your attention to this, Charles:
1 Public Class frmMain
2 '....snip...
3 Private oProcess As System.Diagnost ics.Process
4 '....snip...
5 Friend WithEvents pgAction As System.Windows. Forms.ProgressB ar
6 '....snip...
7 Public Sub New()
8 MyBase.New()
9 'This call is required by the Windows Form Designer.
10 InitializeCompo nent()
11 'Add any initialization after the InitializeCompo nent() call
13 Me.MyMain()
14 End Sub
15 '....snip...
16 Private Sub IncrementAction Progress()
17 While Not oProcess.HasExi ted 'HACK start with a the progress
bar
moving up 2 steps / second
18 If Me.pgAction.Val ue = 100 Then Me.pgAction.Val ue = 0
'Keep
going till thread is aborted...
19 Me.pgAction.Inc rement(1) 'declaration not shown...
20 System.Threadin g.Thread.Curren tThread.Sleep(5 00)
21 End While
22 End Sub
23 '....snip...
24 Private Sub MyMain
25 oProcess = New System.Diagnost ics.Process
26 Try
27 oProcess.StartI nfo.FileName = Process
28 oProcess.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal
29 oProcess.Start( )
30 Dim t As System.Threadin g.Thread
31 t = New System.Threadin g.Thread(Addres sOf
Me.IncrementAct ionProgress)
32 t.Start()
33 oProcess.WaitFo rExit()
34 t.Abort()
35 Me.pgAction.Val ue = Me.pgAction.Max imum 'Ensure that
progress bar goes to max...
36 Catch ex As Exception
37 Msgbox "Error: " & Err.Message 'TODO handle error
gracefully...
38 End Try
39 End Sub

Apr 18 '06 #2
Hi Charles,

The problem is that a Windows Form is STA Threaded. Your threads are
multi-threaded. They cannot operate directly on the Form thread. Instead,
methods on the main thread have to be marshalled to it. There is a good
series of articles in the MSDN library about this. Read all 3 of them
carefully. It's not all that easy to grasp!

http://msdn.microsoft.com/library/de...ms06112002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"hz****@nopost. com" <hz************ *@discussions.m icrosoft.com> wrote in
message news:E2******** *************** ***********@mic rosoft.com...
Using VS 2003, .NET:
I developed a windows application that performs several actions based on
an
input file. The application displays a progress bar as each action
executes.
Based on new requirements, this application needs to be able to shell off
other processes and wait while in the mean time displaying a progress bar
of
the process's. I am using the System.Disgnost ics.Process class to "start"
and "waitForExi t" of these processes... I thought the best way to show
status
was to kick off a separate thread that increments a progress bar on my GUI
while the processes's hasExited value is false... unfortunately this is
not
working well for me. As I step through the code, everything looks good
until
line 11 below executes... after executing this line nothing happens and
the
application just hangs. Being a novice to threads, I wasn't sure if my
application of thread was appropriate in this instance (regardless I
wanted
to try and make it work as a learning exercise). So, Is my application of
a
separate thread appropriate? Should it be implemented differently, etc?
Any
idea why the application just hangs after line 11?

Thanks for your attention to this, Charles:
1 Public Class frmMain
2 '....snip...
3 Private oProcess As System.Diagnost ics.Process
4 '....snip...
5 Friend WithEvents pgAction As System.Windows. Forms.ProgressB ar
6 '....snip...
7 Public Sub New()
8 MyBase.New()
9 'This call is required by the Windows Form Designer.
10 InitializeCompo nent()
11 'Add any initialization after the InitializeCompo nent() call
13 Me.MyMain()
14 End Sub
15 '....snip...
16 Private Sub IncrementAction Progress()
17 While Not oProcess.HasExi ted 'HACK start with a the progress
bar
moving up 2 steps / second
18 If Me.pgAction.Val ue = 100 Then Me.pgAction.Val ue = 0
'Keep
going till thread is aborted...
19 Me.pgAction.Inc rement(1) 'declaration not shown...
20 System.Threadin g.Thread.Curren tThread.Sleep(5 00)
21 End While
22 End Sub
23 '....snip...
24 Private Sub MyMain
25 oProcess = New System.Diagnost ics.Process
26 Try
27 oProcess.StartI nfo.FileName = Process
28 oProcess.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal
29 oProcess.Start( )
30 Dim t As System.Threadin g.Thread
31 t = New System.Threadin g.Thread(Addres sOf
Me.IncrementAct ionProgress)
32 t.Start()
33 oProcess.WaitFo rExit()
34 t.Abort()
35 Me.pgAction.Val ue = Me.pgAction.Max imum 'Ensure that
progress bar goes to max...
36 Catch ex As Exception
37 Msgbox "Error: " & Err.Message 'TODO handle error
gracefully...
38 End Try
39 End Sub

Apr 18 '06 #3
Actually, I do know how many steps (totalsteps) and the expected duration of
the processes to be shelled... the code below was me just trying to see if I
could get it to work...

"Cor Ligthert [MVP]" wrote:
Hi,

If you want to use a progressbar, than you need to know

The Start
The in advance measured time or totalsteps that will be involved
The steps.

You know only the Start so your program makes in my opinion not much sense.

Cor
"hz****@nopost. com" <hz************ *@discussions.m icrosoft.com> schreef in
bericht news:E2******** *************** ***********@mic rosoft.com...
Using VS 2003, .NET:
I developed a windows application that performs several actions based on
an
input file. The application displays a progress bar as each action
executes.
Based on new requirements, this application needs to be able to shell off
other processes and wait while in the mean time displaying a progress bar
of
the process's. I am using the System.Disgnost ics.Process class to "start"
and "waitForExi t" of these processes... I thought the best way to show
status
was to kick off a separate thread that increments a progress bar on my GUI
while the processes's hasExited value is false... unfortunately this is
not
working well for me. As I step through the code, everything looks good
until
line 11 below executes... after executing this line nothing happens and
the
application just hangs. Being a novice to threads, I wasn't sure if my
application of thread was appropriate in this instance (regardless I
wanted
to try and make it work as a learning exercise). So, Is my application of
a
separate thread appropriate? Should it be implemented differently, etc?
Any
idea why the application just hangs after line 11?

Thanks for your attention to this, Charles:
1 Public Class frmMain
2 '....snip...
3 Private oProcess As System.Diagnost ics.Process
4 '....snip...
5 Friend WithEvents pgAction As System.Windows. Forms.ProgressB ar
6 '....snip...
7 Public Sub New()
8 MyBase.New()
9 'This call is required by the Windows Form Designer.
10 InitializeCompo nent()
11 'Add any initialization after the InitializeCompo nent() call
13 Me.MyMain()
14 End Sub
15 '....snip...
16 Private Sub IncrementAction Progress()
17 While Not oProcess.HasExi ted 'HACK start with a the progress
bar
moving up 2 steps / second
18 If Me.pgAction.Val ue = 100 Then Me.pgAction.Val ue = 0
'Keep
going till thread is aborted...
19 Me.pgAction.Inc rement(1) 'declaration not shown...
20 System.Threadin g.Thread.Curren tThread.Sleep(5 00)
21 End While
22 End Sub
23 '....snip...
24 Private Sub MyMain
25 oProcess = New System.Diagnost ics.Process
26 Try
27 oProcess.StartI nfo.FileName = Process
28 oProcess.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal
29 oProcess.Start( )
30 Dim t As System.Threadin g.Thread
31 t = New System.Threadin g.Thread(Addres sOf
Me.IncrementAct ionProgress)
32 t.Start()
33 oProcess.WaitFo rExit()
34 t.Abort()
35 Me.pgAction.Val ue = Me.pgAction.Max imum 'Ensure that
progress bar goes to max...
36 Catch ex As Exception
37 Msgbox "Error: " & Err.Message 'TODO handle error
gracefully...
38 End Try
39 End Sub


Apr 18 '06 #4
Ok, I'll take a read... thanks for the reference.
If I have questions about those articles, I'll post them here.

"Kevin Spencer" wrote:
Hi Charles,

The problem is that a Windows Form is STA Threaded. Your threads are
multi-threaded. They cannot operate directly on the Form thread. Instead,
methods on the main thread have to be marshalled to it. There is a good
series of articles in the MSDN library about this. Read all 3 of them
carefully. It's not all that easy to grasp!

http://msdn.microsoft.com/library/de...ms06112002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"hz****@nopost. com" <hz************ *@discussions.m icrosoft.com> wrote in
message news:E2******** *************** ***********@mic rosoft.com...
Using VS 2003, .NET:
I developed a windows application that performs several actions based on
an
input file. The application displays a progress bar as each action
executes.
Based on new requirements, this application needs to be able to shell off
other processes and wait while in the mean time displaying a progress bar
of
the process's. I am using the System.Disgnost ics.Process class to "start"
and "waitForExi t" of these processes... I thought the best way to show
status
was to kick off a separate thread that increments a progress bar on my GUI
while the processes's hasExited value is false... unfortunately this is
not
working well for me. As I step through the code, everything looks good
until
line 11 below executes... after executing this line nothing happens and
the
application just hangs. Being a novice to threads, I wasn't sure if my
application of thread was appropriate in this instance (regardless I
wanted
to try and make it work as a learning exercise). So, Is my application of
a
separate thread appropriate? Should it be implemented differently, etc?
Any
idea why the application just hangs after line 11?

Thanks for your attention to this, Charles:
1 Public Class frmMain
2 '....snip...
3 Private oProcess As System.Diagnost ics.Process
4 '....snip...
5 Friend WithEvents pgAction As System.Windows. Forms.ProgressB ar
6 '....snip...
7 Public Sub New()
8 MyBase.New()
9 'This call is required by the Windows Form Designer.
10 InitializeCompo nent()
11 'Add any initialization after the InitializeCompo nent() call
13 Me.MyMain()
14 End Sub
15 '....snip...
16 Private Sub IncrementAction Progress()
17 While Not oProcess.HasExi ted 'HACK start with a the progress
bar
moving up 2 steps / second
18 If Me.pgAction.Val ue = 100 Then Me.pgAction.Val ue = 0
'Keep
going till thread is aborted...
19 Me.pgAction.Inc rement(1) 'declaration not shown...
20 System.Threadin g.Thread.Curren tThread.Sleep(5 00)
21 End While
22 End Sub
23 '....snip...
24 Private Sub MyMain
25 oProcess = New System.Diagnost ics.Process
26 Try
27 oProcess.StartI nfo.FileName = Process
28 oProcess.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal
29 oProcess.Start( )
30 Dim t As System.Threadin g.Thread
31 t = New System.Threadin g.Thread(Addres sOf
Me.IncrementAct ionProgress)
32 t.Start()
33 oProcess.WaitFo rExit()
34 t.Abort()
35 Me.pgAction.Val ue = Me.pgAction.Max imum 'Ensure that
progress bar goes to max...
36 Catch ex As Exception
37 Msgbox "Error: " & Err.Message 'TODO handle error
gracefully...
38 End Try
39 End Sub


Apr 18 '06 #5
I read the above articles (second link is duplicated) and implemented some
changes in my code...(no more threading but async calls?) but my GUI still
does not get updated - actually, after the new process is started, my GUI
doesn't get painted again until after that process has completed - so it
appears that this is not working for me... is this because I'm doing all my
work in one class (frmMain)? Anyway, here's the code that I've got now. What
am I doing wrong here?

Public Class frmMain
'....snip...
Private oProcess As System.Diagnost ics.Process
'....snip...
Friend WithEvents pgAction As System.Windows. Forms.ProgressB ar
'....snip...
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
Me.MyMain() 'Process actions...
End Sub
'....snip...
Private Sub IncrementAction Progress()
If Me.pgAction.Inv okeRequired Then
'Show progress asynchronously
Dim iapd As IncrementAction ProgressDelegat e = _
New IncrementAction ProgressDelegat e(AddressOf
IncrementAction Progress)
Me.BeginInvoke( iapd)
Else
If Me.pgAction.Val ue = 100 Then Me.pgAction.Val ue = 0
Me.pgAction.Val ue += 1
Me.Refresh()
System.Threadin g.Thread.Sleep( 500)
End If
End Sub

Delegate Sub IncrementAction ProgressDelegat e()

Private Sub MyMain()
oProcess = New System.Diagnost ics.Process
Try
oProcess.StartI nfo.FileName = Process
Me.pgAction.Val ue = 0
oProcess.Start( )
While Not oProcess.HasExi ted
Me.IncrementAct ionProgress()
End While
oProcess.WaitFo rExit() 'Yes, this is redundant...
Me.pgAction.Val ue = Me.pgAction.Max imum
Catch ex As Exception
'TODO Handle error gracefully
End Try
End Sub
'....snip...
End Class

"Kevin Spencer" wrote:
Hi Charles,

The problem is that a Windows Form is STA Threaded. Your threads are
multi-threaded. They cannot operate directly on the Form thread. Instead,
methods on the main thread have to be marshalled to it. There is a good
series of articles in the MSDN library about this. Read all 3 of them
carefully. It's not all that easy to grasp!

http://msdn.microsoft.com/library/de...ms06112002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"hz****@nopost. com" <hz************ *@discussions.m icrosoft.com> wrote in
message news:E2******** *************** ***********@mic rosoft.com...
Using VS 2003, .NET:
I developed a windows application that performs several actions based on
an
input file. The application displays a progress bar as each action
executes.
Based on new requirements, this application needs to be able to shell off
other processes and wait while in the mean time displaying a progress bar
of
the process's. I am using the System.Disgnost ics.Process class to "start"
and "waitForExi t" of these processes... I thought the best way to show
status
was to kick off a separate thread that increments a progress bar on my GUI
while the processes's hasExited value is false... unfortunately this is
not
working well for me. As I step through the code, everything looks good
until
line 11 below executes... after executing this line nothing happens and
the
application just hangs. Being a novice to threads, I wasn't sure if my
application of thread was appropriate in this instance (regardless I
wanted
to try and make it work as a learning exercise). So, Is my application of
a
separate thread appropriate? Should it be implemented differently, etc?
Any
idea why the application just hangs after line 11?

Thanks for your attention to this, Charles:
1 Public Class frmMain
2 '....snip...
3 Private oProcess As System.Diagnost ics.Process
4 '....snip...
5 Friend WithEvents pgAction As System.Windows. Forms.ProgressB ar
6 '....snip...
7 Public Sub New()
8 MyBase.New()
9 'This call is required by the Windows Form Designer.
10 InitializeCompo nent()
11 'Add any initialization after the InitializeCompo nent() call
13 Me.MyMain()
14 End Sub
15 '....snip...
16 Private Sub IncrementAction Progress()
17 While Not oProcess.HasExi ted 'HACK start with a the progress
bar
moving up 2 steps / second
18 If Me.pgAction.Val ue = 100 Then Me.pgAction.Val ue = 0
'Keep
going till thread is aborted...
19 Me.pgAction.Inc rement(1) 'declaration not shown...
20 System.Threadin g.Thread.Curren tThread.Sleep(5 00)
21 End While
22 End Sub
23 '....snip...
24 Private Sub MyMain
25 oProcess = New System.Diagnost ics.Process
26 Try
27 oProcess.StartI nfo.FileName = Process
28 oProcess.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal
29 oProcess.Start( )
30 Dim t As System.Threadin g.Thread
31 t = New System.Threadin g.Thread(Addres sOf
Me.IncrementAct ionProgress)
32 t.Start()
33 oProcess.WaitFo rExit()
34 t.Abort()
35 Me.pgAction.Val ue = Me.pgAction.Max imum 'Ensure that
progress bar goes to max...
36 Catch ex As Exception
37 Msgbox "Error: " & Err.Message 'TODO handle error
gracefully...
38 End Try
39 End Sub


Apr 18 '06 #6
I do most of my programming in C#, but I'm sure there is a call in
vb.net that coorisponds to the this.Update() or even this.Refresh()
function at form level.

I use this to update my forms when I need it to post info back to the
form before it finishes executing and repaints the form.
hz****@nopost.c om wrote:
I read the above articles (second link is duplicated) and implemented some
changes in my code...(no more threading but async calls?) but my GUI still
does not get updated - actually, after the new process is started, my GUI
doesn't get painted again until after that process has completed - so it
appears that this is not working for me... is this because I'm doing all my
work in one class (frmMain)? Anyway, here's the code that I've got now. What
am I doing wrong here?

Public Class frmMain
'....snip...
Private oProcess As System.Diagnost ics.Process
'....snip...
Friend WithEvents pgAction As System.Windows. Forms.ProgressB ar
'....snip...
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
Me.MyMain() 'Process actions...
End Sub
'....snip...
Private Sub IncrementAction Progress()
If Me.pgAction.Inv okeRequired Then
'Show progress asynchronously
Dim iapd As IncrementAction ProgressDelegat e = _
New IncrementAction ProgressDelegat e(AddressOf
IncrementAction Progress)
Me.BeginInvoke( iapd)
Else
If Me.pgAction.Val ue = 100 Then Me.pgAction.Val ue = 0
Me.pgAction.Val ue += 1
Me.Refresh()
System.Threadin g.Thread.Sleep( 500)
End If
End Sub

Delegate Sub IncrementAction ProgressDelegat e()

Private Sub MyMain()
oProcess = New System.Diagnost ics.Process
Try
oProcess.StartI nfo.FileName = Process
Me.pgAction.Val ue = 0
oProcess.Start( )
While Not oProcess.HasExi ted
Me.IncrementAct ionProgress()
End While
oProcess.WaitFo rExit() 'Yes, this is redundant...
Me.pgAction.Val ue = Me.pgAction.Max imum
Catch ex As Exception
'TODO Handle error gracefully
End Try
End Sub
'....snip...
End Class

"Kevin Spencer" wrote:
Hi Charles,

The problem is that a Windows Form is STA Threaded. Your threads are
multi-threaded. They cannot operate directly on the Form thread. Instead,
methods on the main thread have to be marshalled to it. There is a good
series of articles in the MSDN library about this. Read all 3 of them
carefully. It's not all that easy to grasp!

http://msdn.microsoft.com/library/de...ms06112002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp
http://msdn.microsoft.com/library/de...ms08162002.asp

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"hz****@nopost. com" <hz************ *@discussions.m icrosoft.com> wrote in
message news:E2******** *************** ***********@mic rosoft.com...
Using VS 2003, .NET:
I developed a windows application that performs several actions based on
an
input file. The application displays a progress bar as each action
executes.
Based on new requirements, this application needs to be able to shell off
other processes and wait while in the mean time displaying a progress bar
of
the process's. I am using the System.Disgnost ics.Process class to "start"
and "waitForExi t" of these processes... I thought the best way to show
status
was to kick off a separate thread that increments a progress bar on my GUI
while the processes's hasExited value is false... unfortunately this is
not
working well for me. As I step through the code, everything looks good
until
line 11 below executes... after executing this line nothing happens and
the
application just hangs. Being a novice to threads, I wasn't sure if my
application of thread was appropriate in this instance (regardless I
wanted
to try and make it work as a learning exercise). So, Is my application of
a
separate thread appropriate? Should it be implemented differently, etc?
Any
idea why the application just hangs after line 11?

Thanks for your attention to this, Charles:
1 Public Class frmMain
2 '....snip...
3 Private oProcess As System.Diagnost ics.Process
4 '....snip...
5 Friend WithEvents pgAction As System.Windows. Forms.ProgressB ar
6 '....snip...
7 Public Sub New()
8 MyBase.New()
9 'This call is required by the Windows Form Designer.
10 InitializeCompo nent()
11 'Add any initialization after the InitializeCompo nent() call
13 Me.MyMain()
14 End Sub
15 '....snip...
16 Private Sub IncrementAction Progress()
17 While Not oProcess.HasExi ted 'HACK start with a the progress
bar
moving up 2 steps / second
18 If Me.pgAction.Val ue = 100 Then Me.pgAction.Val ue = 0
'Keep
going till thread is aborted...
19 Me.pgAction.Inc rement(1) 'declaration not shown...
20 System.Threadin g.Thread.Curren tThread.Sleep(5 00)
21 End While
22 End Sub
23 '....snip...
24 Private Sub MyMain
25 oProcess = New System.Diagnost ics.Process
26 Try
27 oProcess.StartI nfo.FileName = Process
28 oProcess.StartI nfo.WindowStyle = ProcessWindowSt yle.Normal
29 oProcess.Start( )
30 Dim t As System.Threadin g.Thread
31 t = New System.Threadin g.Thread(Addres sOf
Me.IncrementAct ionProgress)
32 t.Start()
33 oProcess.WaitFo rExit()
34 t.Abort()
35 Me.pgAction.Val ue = Me.pgAction.Max imum 'Ensure that
progress bar goes to max...
36 Catch ex As Exception
37 Msgbox "Error: " & Err.Message 'TODO handle error
gracefully...
38 End Try
39 End Sub



Apr 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2982
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def get_all_files(path): """return all files of folder path, scan with subfolders
1
1481
by: Ognjen Bezanov | last post by:
Hi, all Thanks all of you who helped me with the threading and queues issue. I am trying to get it working but I am having problems. When I try to run the following: cmddata = mediaplay.initcommandqueue() #initiates the Queue to send commands down
0
1265
by: Maxwell Hammer | last post by:
Hope someone can help with a problem I'm having. A python program I wrote terminates with the following traceback. *** start traceback *** Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/usr/lib/python2.4/atexit.py", line 22, in _run_exitfuncs func(*targs, **kargs) File "/usr/lib/python2.4/threading.py", line 636, in __exitfunc self._Thread__delete()
2
8464
by: hnkien | last post by:
Hi, I am writing a windows service with threading.timer for 10 seconds but it didn't work. Here are my code: namespace SchedulerService { public class ScheduleService : System.ServiceProcess.ServiceBase { private System.ComponentModel.IContainer components; protected System.Threading.Timer tmrThreadingTimer;
22
4067
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
10
1611
by: MikeScullion | last post by:
I have set up this thread so my program doesn't hang while I call a cpu intensive bit of code: System.Threading.ThreadStart ThreadEncoderStart = new System.Threading.ThreadStart(myEncoder.EncodeFromConsole); System.Threading.Thread Thread_myEncoder = new System.Threading.Thread(ThreadEncoderStart); Thread_myEncoder.Name = "myEncoder"; Thread_myEncoder.Priority = System.Threading.ThreadPriority.BelowNormal;
5
3104
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when i used time.sleep in while, the function in while never executed. then i found something about Timer but couldnt realize any algorithm in my mind.
15
2579
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the same messages because each thread gets the recors then sends the message. I need somehow to prevent...
3
12778
by: dedalusenator | last post by:
Hello Folks, My first posting here and I am a stuck in figuring out the exact way to update a global variable from within a function that doesnt return any value (because the function is a target of the thread and I dont know how exactly return would work in such a case). I am sure I am missing something very fundamental here. The essential pieces of my code that cause the problem would be something like this:...
1
1237
by: JoeSox | last post by:
I have two threads going class guiThread(threading.Thread) class mainThread(threading.Thread) Within the guiThread, I have an instance of class GUIFramework(Frame) in this Tkinter instance I have a ListBox. The second thread, mainThread, has an instance of a custom class the will need to send out text or other objects to the gui.
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.