473,841 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Waiting of process completion

How to wait for a process to stop completion is my goal. Obviously, the
looping while waiting for the HasExited property is not a solution.. but
thats the best I can come up off the top of my head. Natuarally it will not
work. I expect it to use up all resources looping, which will not allow the
process to complete. The process takes about 60 seconds, because the .bat
file it is calling is rebuilding mulitple .NET solutions and projects and
copying the assembly files out to other directories.

So in short, I'm looking for an efficient way to wait for the process to
complete before continuting to execute the remainder of the code in the Sub.

I have the following code (only what you need to help me, if you need to see
more, let me know, but the government doesn't like me putting a bunch of
source code out there if it isn't relevant.):

*************** *************** *************** *
Public Class frmMerge

Private processRebuildA W As Process

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click

ClearListBox()

ClearProgressBa r()

#If Not Debug Then
IF chkRebuildAW.Ch ecked = True Then RebuildAWPath()

Do While Not (processRebuild AW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.Sta rtupPath & "\rebuildawpath .bat"

processRebuildA W = Process.Start(s trPath)

End Sub

End Class

*************** *************** *************** *


Nov 20 '05 #1
12 2382
have you tried to use a delegate to call your method asyncronously? That
way you can have an AsyncCallBack method to be invoked when your method is
done, so your not polling your process (or at least do it asynchounsly so
you can give control back to the user)

-CJ

FAA hiring?

=)
"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
How to wait for a process to stop completion is my goal. Obviously, the
looping while waiting for the HasExited property is not a solution.. but
thats the best I can come up off the top of my head. Natuarally it will not work. I expect it to use up all resources looping, which will not allow the process to complete. The process takes about 60 seconds, because the .bat
file it is calling is rebuilding mulitple .NET solutions and projects and
copying the assembly files out to other directories.

So in short, I'm looking for an efficient way to wait for the process to
complete before continuting to execute the remainder of the code in the Sub.
I have the following code (only what you need to help me, if you need to see more, let me know, but the government doesn't like me putting a bunch of
source code out there if it isn't relevant.):

*************** *************** *************** *
Public Class frmMerge

Private processRebuildA W As Process

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click

ClearListBox()

ClearProgressBa r()

#If Not Debug Then
IF chkRebuildAW.Ch ecked = True Then RebuildAWPath()

Do While Not (processRebuild AW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.Sta rtupPath & "\rebuildawpath .bat"

processRebuildA W = Process.Start(s trPath)

End Sub

End Class

*************** *************** *************** *

Nov 20 '05 #2
Cor
Hi Raymond,

I did not look at your solution before, but now I see it I think it starts a
shell proces, and I understand you want to wait until that is ready.

I think that the solution is very simple place this behind your start of the
batch file. It has to wait for the last standardOutput and therefore to wait
until that program is ready.

I hope that I did understand that problem well?

Cor

\\\
p.Start()
Dim sr As IO.StreamReader = p.StandardOutpu t
Dim sb As New System.Text.Str ingBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW( input))
input = sr.Read
Loop
///
Nov 20 '05 #3
CJ,

Please look at the following changes. I have run this and its just keep
right on executing the remainder of the code in the sub without waiting for
the batch file to complete first. The reason I need to batch file to
complete first is because it is rebuilding .NET assemblies that the
remainder of the sub is going to use, therefore they need to be built first
and copied, which is what the .bat file does, and then the remainder of the
code can run.

Thanks for you help, you're helping out with a problem I really don't want
to have to work around.

Now I have the following:

*************** *************** *************** *
Public Class frmMerge

Private processRebuildA W As Process
Delegate Sub AsyncRebuildAW( )

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click

ClearListBox()

ClearProgressBa r()

#If Not Debug Then

If chkRebuildAW.Ch ecked = True Then

Dim objAsync As New AsyncRebuildAW( AddressOf RebuildAWPath)

Dim objResult As IAsyncResult = objAsync.BeginI nvoke(Nothing, Nothing)

Do Until objResult.IsCom pleted

Loop

objAsync.EndInv oke(objResult)

End If
#End If

lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.Sta rtupPath & "\rebuildawpath .bat"

processRebuildA W = Process.Start(s trPath)

End Sub

End Class

*************** *************** *************** *

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
have you tried to use a delegate to call your method asyncronously? That
way you can have an AsyncCallBack method to be invoked when your method is
done, so your not polling your process (or at least do it asynchounsly so
you can give control back to the user)

-CJ

FAA hiring?

=)
"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
How to wait for a process to stop completion is my goal. Obviously, the
looping while waiting for the HasExited property is not a solution.. but
thats the best I can come up off the top of my head. Natuarally it will

not
work. I expect it to use up all resources looping, which will not allow

the
process to complete. The process takes about 60 seconds, because the ..bat file it is calling is rebuilding mulitple .NET solutions and projects and copying the assembly files out to other directories.

So in short, I'm looking for an efficient way to wait for the process to
complete before continuting to execute the remainder of the code in the

Sub.

I have the following code (only what you need to help me, if you need to

see
more, let me know, but the government doesn't like me putting a bunch of
source code out there if it isn't relevant.):

*************** *************** *************** *
Public Class frmMerge

Private processRebuildA W As Process

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click

ClearListBox()

ClearProgressBa r()

#If Not Debug Then
IF chkRebuildAW.Ch ecked = True Then RebuildAWPath()

Do While Not (processRebuild AW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.Sta rtupPath & "\rebuildawpath .bat"
processRebuildA W = Process.Start(s trPath)

End Sub

End Class

*************** *************** *************** *


Nov 20 '05 #4
Cor,

Is the solution below attempting to capture output from the DOS shell? If
so, will this looping put me back into the same situation I'm trying to get
out of, which is the looping is using so much computer resources, that the
DOS shell can't finish whats its trying to do due to lack of resources/CPU
availability?

Thanks for your help. In waiting for your response, I will go ahead and
implement what you have given me below. Taking the time from your day to
help me is greatly appreciated.

Raymond Lewallen

"Cor" <no*@non.com> wrote in message
news:OQ******** ******@TK2MSFTN GP11.phx.gbl...
Hi Raymond,

I did not look at your solution before, but now I see it I think it starts a shell proces, and I understand you want to wait until that is ready.

I think that the solution is very simple place this behind your start of the batch file. It has to wait for the last standardOutput and therefore to wait until that program is ready.

I hope that I did understand that problem well?

Cor

\\\
p.Start()
Dim sr As IO.StreamReader = p.StandardOutpu t
Dim sb As New System.Text.Str ingBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW( input))
input = sr.Read
Loop
///

Nov 20 '05 #5
CJ,

Regarding the FAA hiring: the best way to attempt to get into the FAA, or
any other government agency as a IT person, regardless of network, software,
security etc.. is to get on as a contractor first. I'll tell you how I got
on... go to http://www.lockheedmartin.com click on Careers-Submit a Resume.
Give them your information, as they are a very, very large provider of IT
professionals to the US Gov't. Took me 6 months before I ever got a call
from LMIT (Lockheed-Martin Information Technology) after submitting my
resume, but the end result and current job was worth waiting the 6 months
for, even if I did have to sell cars in the meantime :) If you do put in
your resume, put me down as a referal. They pay me money for hiring
referals :)

Hope this information helps anyone out there looking to get a foot into the
door of government software development. Its a great opportunity if
available and offered to you, IMO.

Raymond Lewallen

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
have you tried to use a delegate to call your method asyncronously? That
way you can have an AsyncCallBack method to be invoked when your method is
done, so your not polling your process (or at least do it asynchounsly so
you can give control back to the user)

-CJ

FAA hiring?

=)
"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
How to wait for a process to stop completion is my goal. Obviously, the
looping while waiting for the HasExited property is not a solution.. but
thats the best I can come up off the top of my head. Natuarally it will

not
work. I expect it to use up all resources looping, which will not allow

the
process to complete. The process takes about 60 seconds, because the ..bat file it is calling is rebuilding mulitple .NET solutions and projects and copying the assembly files out to other directories.

So in short, I'm looking for an efficient way to wait for the process to
complete before continuting to execute the remainder of the code in the

Sub.

I have the following code (only what you need to help me, if you need to

see
more, let me know, but the government doesn't like me putting a bunch of
source code out there if it isn't relevant.):

*************** *************** *************** *
Public Class frmMerge

Private processRebuildA W As Process

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click

ClearListBox()

ClearProgressBa r()

#If Not Debug Then
IF chkRebuildAW.Ch ecked = True Then RebuildAWPath()

Do While Not (processRebuild AW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.Sta rtupPath & "\rebuildawpath .bat"
processRebuildA W = Process.Start(s trPath)

End Sub

End Class

*************** *************** *************** *


Nov 20 '05 #6
Raymond,

Thanks for the FAA info.. now regarding your problem.

Screw the do until loop, your just wasting time and not ever returning
control back to the user. Doing it that way, you might as well just call
the method directly.

on your async delegate, the first parameter is another delegate to a
callback method. Create another method that has the signature

private sub callbackmethod( ar as IAsyncResult)

Dim asyncR as AsyncResult ' this is in System.runtime. remoting.messag ing
namespace

asyncR = ctype(ar, AsyncResult)

dim asyncDel as AsyncRebuildAW

asyncDel = Ctype(asyncR.As yncDelegate, AsyncrebuildAw)

asyncDel.EndInv oke(ar)

'now process whatever you want from your batch file... this means its
executed

end sub

And thats about all she wrote.. hope it helps.

-CJ

"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message
news:uj******** ******@TK2MSFTN GP12.phx.gbl...
CJ,

Please look at the following changes. I have run this and its just keep
right on executing the remainder of the code in the sub without waiting for the batch file to complete first. The reason I need to batch file to
complete first is because it is rebuilding .NET assemblies that the
remainder of the sub is going to use, therefore they need to be built first and copied, which is what the .bat file does, and then the remainder of the code can run.

Thanks for you help, you're helping out with a problem I really don't want
to have to work around.

Now I have the following:

*************** *************** *************** *
Public Class frmMerge

Private processRebuildA W As Process
Delegate Sub AsyncRebuildAW( )

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click

ClearListBox()

ClearProgressBa r()

#If Not Debug Then

If chkRebuildAW.Ch ecked = True Then

Dim objAsync As New AsyncRebuildAW( AddressOf RebuildAWPath)

Dim objResult As IAsyncResult = objAsync.BeginI nvoke(Nothing, Nothing)

Do Until objResult.IsCom pleted

Loop

objAsync.EndInv oke(objResult)

End If
#End If

lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.Sta rtupPath & "\rebuildawpath .bat"
processRebuildA W = Process.Start(s trPath)

End Sub

End Class

*************** *************** *************** *

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
have you tried to use a delegate to call your method asyncronously? That
way you can have an AsyncCallBack method to be invoked when your method is done, so your not polling your process (or at least do it asynchounsly so you can give control back to the user)

-CJ

FAA hiring?

=)
"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message news:%2******** *******@tk2msft ngp13.phx.gbl.. .
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my head. Natuarally it will
not
work. I expect it to use up all resources looping, which will not
allow the
process to complete. The process takes about 60 seconds, because the .bat file it is calling is rebuilding mulitple .NET solutions and projects and copying the assembly files out to other directories.

So in short, I'm looking for an efficient way to wait for the process
to complete before continuting to execute the remainder of the code in the Sub.

I have the following code (only what you need to help me, if you need
to see
more, let me know, but the government doesn't like me putting a bunch

of source code out there if it isn't relevant.):

*************** *************** *************** *
Public Class frmMerge

Private processRebuildA W As Process

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click

ClearListBox()

ClearProgressBa r()

#If Not Debug Then
IF chkRebuildAW.Ch ecked = True Then RebuildAWPath()

Do While Not (processRebuild AW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.Sta rtupPath &

"\rebuildawpath .bat"
processRebuildA W = Process.Start(s trPath)

End Sub

End Class

*************** *************** *************** *



Nov 20 '05 #7
Now i have the following, but the code below "NOTHING BELOW IS BEING
EXECUTED" is doing just that, not executing.

Sorry to be such a bother, I'm a DBA working in about 12 different .NET
projects at the moment, and this code is a side project to help me manage
the building of assemblies and merging of projects of the other 12.

Again, there is another 850 lines of code I've excluded, but those are not
relevant to this situation.

Thanks for all you help,

Raymond Lewallen

Public Class frmMerge
Inherits System.Windows. Forms.Form

Private processRebuildA W As Process
Delegate Sub AsyncRebuildAW( )

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click
ClearListBox()
ClearProgressBa r()
If chkRebuildAW.Ch ecked = True Then
Dim objAsync As New AsyncRebuildAW( AddressOf RebuildAWPath)
Dim objCB As New AsyncCallback(A ddressOf callbackmethod)
Dim objAR As IAsyncResult
objAR = objAsync.BeginI nvoke(Nothing, objCB)
End If
End Sub

Private Sub RebuildAWPath()
Dim strPath As String = Application.Sta rtupPath &
"\rebuildawpath .bat"
processRebuildA W = Process.Start(s trPath)
End Sub

Private Sub callbackmethod( ByVal ar As IAsyncResult)
Dim asyncR As System.runtime. remoting.messag ing.AsyncResult ' this
is in System.runtime. remoting.messag ing namespace
asyncR = CType(ar, System.runtime. remoting.messag ing.AsyncResult )
Dim asyncDel As AsyncRebuildAW
asyncDel = CType(asyncR.As yncDelegate, AsyncRebuildAW)
asyncDel.EndInv oke(ar)

' *************** *************** ***************
' *** NOTHING BELOW IS BEING EXECUTED.
' *************** *************** ***************
Dim itemChecked As Object
Dim strCheckedFile As String
Dim strMovedFile As String
For Each itemChecked In clbFiles.Checke dItems
strCheckedFile = itemChecked.ToS tring()
If InStr(strChecke dFile, txtACRADirector y.Text) > 0 Then
strMovedFile = Replace(strChec kedFile,
txtACRADirector y.Text, txtMergeDirecto ry.Text)
ElseIf InStr(strChecke dFile, txtAWDirectory. Text) > 0 Then
strMovedFile = Replace(strChec kedFile,
txtAWDirectory. Text, txtMergeDirecto ry.Text)
Else
strMovedFile = strCheckedFile
End If
lstFiles.Items. Add(strMovedFil e)
Next
lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)
If lstFiles.Items. Count > 0 Then
btnWebsite.Enab led = True
Else
btnWebsite.Enab led = False
End If
lstFiles.Sorted = True
End Sub

End Class

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
Raymond,

Thanks for the FAA info.. now regarding your problem.

Screw the do until loop, your just wasting time and not ever returning
control back to the user. Doing it that way, you might as well just call
the method directly.

on your async delegate, the first parameter is another delegate to a
callback method. Create another method that has the signature

private sub callbackmethod( ar as IAsyncResult)

Dim asyncR as AsyncResult ' this is in System.runtime. remoting.messag ing namespace

asyncR = ctype(ar, AsyncResult)

dim asyncDel as AsyncRebuildAW

asyncDel = Ctype(asyncR.As yncDelegate, AsyncrebuildAw)

asyncDel.EndInv oke(ar)

'now process whatever you want from your batch file... this means its
executed

end sub

And thats about all she wrote.. hope it helps.

-CJ

"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message
news:uj******** ******@TK2MSFTN GP12.phx.gbl...
CJ,

Please look at the following changes. I have run this and its just keep
right on executing the remainder of the code in the sub without waiting for
the batch file to complete first. The reason I need to batch file to
complete first is because it is rebuilding .NET assemblies that the
remainder of the sub is going to use, therefore they need to be built

first
and copied, which is what the .bat file does, and then the remainder of

the
code can run.

Thanks for you help, you're helping out with a problem I really don't want
to have to work around.

Now I have the following:

*************** *************** *************** *
Public Class frmMerge

Private processRebuildA W As Process
Delegate Sub AsyncRebuildAW( )

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click

ClearListBox()

ClearProgressBa r()

#If Not Debug Then

If chkRebuildAW.Ch ecked = True Then

Dim objAsync As New AsyncRebuildAW( AddressOf RebuildAWPath)

Dim objResult As IAsyncResult = objAsync.BeginI nvoke(Nothing, Nothing)

Do Until objResult.IsCom pleted

Loop

objAsync.EndInv oke(objResult)

End If
#End If

lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.Sta rtupPath &

"\rebuildawpath .bat"

processRebuildA W = Process.Start(s trPath)

End Sub

End Class

*************** *************** *************** *

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
have you tried to use a delegate to call your method asyncronously? That way you can have an AsyncCallBack method to be invoked when your method is
done, so your not polling your process (or at least do it asynchounsly
so you can give control back to the user)

-CJ

FAA hiring?

=)
"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message news:%2******** *******@tk2msft ngp13.phx.gbl.. .
> How to wait for a process to stop completion is my goal. Obviously, the > looping while waiting for the HasExited property is not a solution.. but > thats the best I can come up off the top of my head. Natuarally it will not
> work. I expect it to use up all resources looping, which will not allow the
> process to complete. The process takes about 60 seconds, because
the .bat
> file it is calling is rebuilding mulitple .NET solutions and
projects and
> copying the assembly files out to other directories.
>
> So in short, I'm looking for an efficient way to wait for the
process to > complete before continuting to execute the remainder of the code in the Sub.
>
> I have the following code (only what you need to help me, if you
need
to see
> more, let me know, but the government doesn't like me putting a
bunch
of > source code out there if it isn't relevant.):
>
> *************** *************** *************** *
> Public Class frmMerge
>
> Private processRebuildA W As Process
>
> Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e

As > System.EventArg s) Handles btnCreate.Click
>
> ClearListBox()
>
> ClearProgressBa r()
>
> #If Not Debug Then
> IF chkRebuildAW.Ch ecked = True Then RebuildAWPath()
>
> Do While Not (processRebuild AW.HasExited)
>
> ' RIGHT HERE IS MY PROBLEM
>
> Loop
>
>
>
> #End If
>
> lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)
>
> blah blah blah more code more code more code
>
> End Sub
>
> Private Sub RebuildAWPath()
>
> Dim strPath As String = Application.Sta rtupPath &

"\rebuildawpath .bat"
>
> processRebuildA W = Process.Start(s trPath)
>
> End Sub
>
> End Class
>
> *************** *************** *************** *
>
>
>
>



Nov 20 '05 #8
Hmmm... forgot that Process.Start() executes on a separate thread. I take
it that it was jupming pretty quick from the process start to the callback.

Anyways, we need to watch for the exiting. Now we can do this through an
event, but lets not waste any more time, your busy as I can tell.

Anyways, here is where we want to do our looping. just do a simple while
not Process.HasExit ed
... sleep, I dunno, whatever.

and then when it does exit, your call back will be properly called and you
wont hang on the EndInvoke.

Try it out and let me know.

-CJ

"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message
news:uh******** ******@TK2MSFTN GP09.phx.gbl...
Now i have the following, but the code below "NOTHING BELOW IS BEING
EXECUTED" is doing just that, not executing.

Sorry to be such a bother, I'm a DBA working in about 12 different .NET
projects at the moment, and this code is a side project to help me manage
the building of assemblies and merging of projects of the other 12.

Again, there is another 850 lines of code I've excluded, but those are not
relevant to this situation.

Thanks for all you help,

Raymond Lewallen

Public Class frmMergea
Inherits System.Windows. Forms.Form

Private processRebuildA W As Process
Delegate Sub AsyncRebuildAW( )

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click
ClearListBox()
ClearProgressBa r()
If chkRebuildAW.Ch ecked = True Then
Dim objAsync As New AsyncRebuildAW( AddressOf RebuildAWPath) Dim objCB As New AsyncCallback(A ddressOf callbackmethod)
Dim objAR As IAsyncResult
objAR = objAsync.BeginI nvoke(Nothing, objCB)
End If
End Sub

Private Sub RebuildAWPath()
Dim strPath As String = Application.Sta rtupPath &
"\rebuildawpath .bat"
processRebuildA W = Process.Start(s trPath)
End Sub

Private Sub callbackmethod( ByVal ar As IAsyncResult)
Dim asyncR As System.runtime. remoting.messag ing.AsyncResult ' this
is in System.runtime. remoting.messag ing namespace
asyncR = CType(ar, System.runtime. remoting.messag ing.AsyncResult )
Dim asyncDel As AsyncRebuildAW
asyncDel = CType(asyncR.As yncDelegate, AsyncRebuildAW)
asyncDel.EndInv oke(ar)

' *************** *************** ***************
' *** NOTHING BELOW IS BEING EXECUTED.
' *************** *************** ***************
Dim itemChecked As Object
Dim strCheckedFile As String
Dim strMovedFile As String
For Each itemChecked In clbFiles.Checke dItems
strCheckedFile = itemChecked.ToS tring()
If InStr(strChecke dFile, txtACRADirector y.Text) > 0 Then
strMovedFile = Replace(strChec kedFile,
txtACRADirector y.Text, txtMergeDirecto ry.Text)
ElseIf InStr(strChecke dFile, txtAWDirectory. Text) > 0 Then
strMovedFile = Replace(strChec kedFile,
txtAWDirectory. Text, txtMergeDirecto ry.Text)
Else
strMovedFile = strCheckedFile
End If
lstFiles.Items. Add(strMovedFil e)
Next
lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)
If lstFiles.Items. Count > 0 Then
btnWebsite.Enab led = True
Else
btnWebsite.Enab led = False
End If
lstFiles.Sorted = True
End Sub

End Class

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
Raymond,

Thanks for the FAA info.. now regarding your problem.

Screw the do until loop, your just wasting time and not ever returning
control back to the user. Doing it that way, you might as well just call
the method directly.

on your async delegate, the first parameter is another delegate to a
callback method. Create another method that has the signature

private sub callbackmethod( ar as IAsyncResult)

Dim asyncR as AsyncResult ' this is in System.runtime. remoting.messag ing
namespace

asyncR = ctype(ar, AsyncResult)

dim asyncDel as AsyncRebuildAW

asyncDel = Ctype(asyncR.As yncDelegate, AsyncrebuildAw)

asyncDel.EndInv oke(ar)

'now process whatever you want from your batch file... this means its
executed

end sub

And thats about all she wrote.. hope it helps.

-CJ

"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message news:uj******** ******@TK2MSFTN GP12.phx.gbl...
CJ,

Please look at the following changes. I have run this and its just keep right on executing the remainder of the code in the sub without
waiting for
the batch file to complete first. The reason I need to batch file to
complete first is because it is rebuilding .NET assemblies that the
remainder of the sub is going to use, therefore they need to be built

first
and copied, which is what the .bat file does, and then the remainder
of the
code can run.

Thanks for you help, you're helping out with a problem I really don't want to have to work around.

Now I have the following:

*************** *************** *************** *
Public Class frmMerge

Private processRebuildA W As Process
Delegate Sub AsyncRebuildAW( )

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click

ClearListBox()

ClearProgressBa r()

#If Not Debug Then

If chkRebuildAW.Ch ecked = True Then

Dim objAsync As New AsyncRebuildAW( AddressOf RebuildAWPath)

Dim objResult As IAsyncResult = objAsync.BeginI nvoke(Nothing, Nothing)

Do Until objResult.IsCom pleted

Loop

objAsync.EndInv oke(objResult)

End If
#End If

lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.Sta rtupPath &

"\rebuildawpath .bat"

processRebuildA W = Process.Start(s trPath)

End Sub

End Class

*************** *************** *************** *

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
> have you tried to use a delegate to call your method asyncronously?

That
> way you can have an AsyncCallBack method to be invoked when your method
is
> done, so your not polling your process (or at least do it

asynchounsly
so
> you can give control back to the user)
>
> -CJ
>
> FAA hiring?
>
> =)
> "Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in

message
> news:%2******** *******@tk2msft ngp13.phx.gbl.. .
> > How to wait for a process to stop completion is my goal.

Obviously, the
> > looping while waiting for the HasExited property is not a
solution.. but
> > thats the best I can come up off the top of my head. Natuarally
it will
> not
> > work. I expect it to use up all resources looping, which will not

allow
> the
> > process to complete. The process takes about 60 seconds, because the .bat
> > file it is calling is rebuilding mulitple .NET solutions and projects and
> > copying the assembly files out to other directories.
> >
> > So in short, I'm looking for an efficient way to wait for the process
to
> > complete before continuting to execute the remainder of the code

in the
> Sub.
> >
> > I have the following code (only what you need to help me, if you

need
to
> see
> > more, let me know, but the government doesn't like me putting a

bunch
of
> > source code out there if it isn't relevant.):
> >
> > *************** *************** *************** *
> > Public Class frmMerge
> >
> > Private processRebuildA W As Process
> >
> > Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e

As > > System.EventArg s) Handles btnCreate.Click
> >
> > ClearListBox()
> >
> > ClearProgressBa r()
> >
> > #If Not Debug Then
> > IF chkRebuildAW.Ch ecked = True Then RebuildAWPath()
> >
> > Do While Not (processRebuild AW.HasExited)
> >
> > ' RIGHT HERE IS MY PROBLEM
> >
> > Loop
> >
> >
> >
> > #End If
> >
> > lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)
> >
> > blah blah blah more code more code more code
> >
> > End Sub
> >
> > Private Sub RebuildAWPath()
> >
> > Dim strPath As String = Application.Sta rtupPath &
"\rebuildawpath .bat"
> >
> > processRebuildA W = Process.Start(s trPath)
> >
> > End Sub
> >
> > End Class
> >
> > *************** *************** *************** *
> >
> >
> >
> >
>
>



Nov 20 '05 #9
CJ,

Thanks for all your help. I took out all the delegate stuff and just
inserted:
do while not (processRebuild AW.HasExited)
System.Threadin g.Thread.Sleep( 1500)
loop
After my call to the sub that launches process.start and that seems to be
working fine now. Thought there might be a cleaner way to do this, but at
this point I just wanted it to work :)

You've been a great help. Sorry for not understanding better, like I said,
I'm an MCDBA but have been doing .NET coding for about 8 months now and
don't understand as much as I would like about more complex .NET scenarios;
complex to me, anyways :) .

Thanks for helping me get going on this. I believe I can release it to the
senior developers now. That was the only hitch I had left to solve.
When/If you have time/get bored I would like to know how to handle this
through an event. I may work on it this weekend. We have a code freeze on
the 7th of April and a rollout on the 30th of April, so I'll have some time
to fine tune this between those dates as well while QA does its part.

Raymond Lewallen
"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
Hmmm... forgot that Process.Start() executes on a separate thread. I take
it that it was jupming pretty quick from the process start to the callback.
Anyways, we need to watch for the exiting. Now we can do this through an
event, but lets not waste any more time, your busy as I can tell.

Anyways, here is where we want to do our looping. just do a simple while
not Process.HasExit ed
... sleep, I dunno, whatever.

and then when it does exit, your call back will be properly called and you
wont hang on the EndInvoke.

Try it out and let me know.

-CJ

"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message
news:uh******** ******@TK2MSFTN GP09.phx.gbl...
Now i have the following, but the code below "NOTHING BELOW IS BEING
EXECUTED" is doing just that, not executing.

Sorry to be such a bother, I'm a DBA working in about 12 different .NET
projects at the moment, and this code is a side project to help me manage
the building of assemblies and merging of projects of the other 12.

Again, there is another 850 lines of code I've excluded, but those are not relevant to this situation.

Thanks for all you help,

Raymond Lewallen

Public Class frmMergea
Inherits System.Windows. Forms.Form

Private processRebuildA W As Process
Delegate Sub AsyncRebuildAW( )

Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCreate.Click
ClearListBox()
ClearProgressBa r()
If chkRebuildAW.Ch ecked = True Then
Dim objAsync As New AsyncRebuildAW( AddressOf

RebuildAWPath)
Dim objCB As New AsyncCallback(A ddressOf callbackmethod)
Dim objAR As IAsyncResult
objAR = objAsync.BeginI nvoke(Nothing, objCB)
End If
End Sub

Private Sub RebuildAWPath()
Dim strPath As String = Application.Sta rtupPath &
"\rebuildawpath .bat"
processRebuildA W = Process.Start(s trPath)
End Sub

Private Sub callbackmethod( ByVal ar As IAsyncResult)
Dim asyncR As System.runtime. remoting.messag ing.AsyncResult ' this is in System.runtime. remoting.messag ing namespace
asyncR = CType(ar, System.runtime. remoting.messag ing.AsyncResult ) Dim asyncDel As AsyncRebuildAW
asyncDel = CType(asyncR.As yncDelegate, AsyncRebuildAW)
asyncDel.EndInv oke(ar)

' *************** *************** ***************
' *** NOTHING BELOW IS BEING EXECUTED.
' *************** *************** ***************
Dim itemChecked As Object
Dim strCheckedFile As String
Dim strMovedFile As String
For Each itemChecked In clbFiles.Checke dItems
strCheckedFile = itemChecked.ToS tring()
If InStr(strChecke dFile, txtACRADirector y.Text) > 0 Then
strMovedFile = Replace(strChec kedFile,
txtACRADirector y.Text, txtMergeDirecto ry.Text)
ElseIf InStr(strChecke dFile, txtAWDirectory. Text) > 0 Then strMovedFile = Replace(strChec kedFile,
txtAWDirectory. Text, txtMergeDirecto ry.Text)
Else
strMovedFile = strCheckedFile
End If
lstFiles.Items. Add(strMovedFil e)
Next
lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)
If lstFiles.Items. Count > 0 Then
btnWebsite.Enab led = True
Else
btnWebsite.Enab led = False
End If
lstFiles.Sorted = True
End Sub

End Class

"CJ Taylor" <no****@blowgoa ts.com> wrote in message
news:10******** *****@corp.supe rnews.com...
Raymond,

Thanks for the FAA info.. now regarding your problem.

Screw the do until loop, your just wasting time and not ever returning
control back to the user. Doing it that way, you might as well just call the method directly.

on your async delegate, the first parameter is another delegate to a
callback method. Create another method that has the signature

private sub callbackmethod( ar as IAsyncResult)

Dim asyncR as AsyncResult ' this is in

System.runtime. remoting.messag ing
namespace

asyncR = ctype(ar, AsyncResult)

dim asyncDel as AsyncRebuildAW

asyncDel = Ctype(asyncR.As yncDelegate, AsyncrebuildAw)

asyncDel.EndInv oke(ar)

'now process whatever you want from your batch file... this means its
executed

end sub

And thats about all she wrote.. hope it helps.

-CJ

"Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in message news:uj******** ******@TK2MSFTN GP12.phx.gbl...
> CJ,
>
> Please look at the following changes. I have run this and its just keep > right on executing the remainder of the code in the sub without waiting for
> the batch file to complete first. The reason I need to batch file to > complete first is because it is rebuilding .NET assemblies that the
> remainder of the sub is going to use, therefore they need to be built first
> and copied, which is what the .bat file does, and then the remainder of the
> code can run.
>
> Thanks for you help, you're helping out with a problem I really don't want
> to have to work around.
>
> Now I have the following:
>
> *************** *************** *************** *
> Public Class frmMerge
>
> Private processRebuildA W As Process
> Delegate Sub AsyncRebuildAW( )
>
> Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e
As > System.EventArg s) Handles btnCreate.Click
>
> ClearListBox()
>
> ClearProgressBa r()
>
> #If Not Debug Then
>
> If chkRebuildAW.Ch ecked = True Then
>
> Dim objAsync As New AsyncRebuildAW( AddressOf RebuildAWPath)
>
> Dim objResult As IAsyncResult = objAsync.BeginI nvoke(Nothing, Nothing) >
> Do Until objResult.IsCom pleted
>
> Loop
>
> objAsync.EndInv oke(objResult)
>
> End If
>
>
> #End If
>
> lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)
>
> blah blah blah more code more code more code
>
> End Sub
>
> Private Sub RebuildAWPath()
>
> Dim strPath As String = Application.Sta rtupPath &
"\rebuildawpath .bat"
>
> processRebuildA W = Process.Start(s trPath)
>
> End Sub
>
> End Class
>
> *************** *************** *************** *
>
> "CJ Taylor" <no****@blowgoa ts.com> wrote in message
> news:10******** *****@corp.supe rnews.com...
> > have you tried to use a delegate to call your method asyncronously? That
> > way you can have an AsyncCallBack method to be invoked when your

method
is
> > done, so your not polling your process (or at least do it asynchounsly
so
> > you can give control back to the user)
> >
> > -CJ
> >
> > FAA hiring?
> >
> > =)
> > "Raymond Lewallen" <Ra************ ******@nospam.f aa.gov> wrote in
message
> > news:%2******** *******@tk2msft ngp13.phx.gbl.. .
> > > How to wait for a process to stop completion is my goal.

Obviously, the
> > > looping while waiting for the HasExited property is not a solution.. but
> > > thats the best I can come up off the top of my head. Natuarally it will
> > not
> > > work. I expect it to use up all resources looping, which will not allow
> > the
> > > process to complete. The process takes about 60 seconds,
because the
> .bat
> > > file it is calling is rebuilding mulitple .NET solutions and

projects
> and
> > > copying the assembly files out to other directories.
> > >
> > > So in short, I'm looking for an efficient way to wait for the

process
to
> > > complete before continuting to execute the remainder of the code in the
> > Sub.
> > >
> > > I have the following code (only what you need to help me, if you

need
to
> > see
> > > more, let me know, but the government doesn't like me putting a

bunch
of
> > > source code out there if it isn't relevant.):
> > >
> > > *************** *************** *************** *
> > > Public Class frmMerge
> > >
> > > Private processRebuildA W As Process
> > >
> > > Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal

e As
> > > System.EventArg s) Handles btnCreate.Click
> > >
> > > ClearListBox()
> > >
> > > ClearProgressBa r()
> > >
> > > #If Not Debug Then
> > > IF chkRebuildAW.Ch ecked = True Then RebuildAWPath()
> > >
> > > Do While Not (processRebuild AW.HasExited)
> > >
> > > ' RIGHT HERE IS MY PROBLEM
> > >
> > > Loop
> > >
> > >
> > >
> > > #End If
> > >
> > > lblReadyCount.T ext = Convert.ToStrin g(lstFiles.Item s.Count)
> > >
> > > blah blah blah more code more code more code
> > >
> > > End Sub
> > >
> > > Private Sub RebuildAWPath()
> > >
> > > Dim strPath As String = Application.Sta rtupPath &
> "\rebuildawpath .bat"
> > >
> > > processRebuildA W = Process.Start(s trPath)
> > >
> > > End Sub
> > >
> > > End Class
> > >
> > > *************** *************** *************** *
> > >
> > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #10

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

Similar topics

18
4899
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
4
6604
by: Prince Kumar | last post by:
I joined a company recently and they have a java program which hangs (does nothing) after a while. This is no way consistent. It could succeed quite a few times and can fail a few other times. There is no consistency when it fails. Could anyone here shed some light on how to debug/resolve the issue. I guess IBM looked at the issue and were not able to pinpoint where the issue is. When the program hangs and when force the DB2...
6
3209
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked list within a single object, which is then placed on a stack(This cuts down thread creation and deletions roughly by a factor of 4). I create up to 12 threads, which then process a single object off of the stack. I use a loop with a boolean...
2
4718
by: objectref | last post by:
hi to all folks, i want to create the following senario: i have a T1 (Thread 1) that acts like http server that receives incoming requests. From that T1, i want to spawn from T1 to Tn thread jobs and beeing able to be notified when each of these threads finished it's job.
2
1274
by: Lucky | last post by:
Hi guys, it's me again. today i'm trying the "Process" class. I'm trying to uninstall one product developed by my company thorugh ..net code but it seems not working but when i execute the commandline MSI uninstall command it seems working fine. the code i'm using is: System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.CreateNoWindow = true; p.StartInfo.FileName =...
13
5138
by: bayer.justin | last post by:
Hi, I am trying to communicate with a subprocess via the subprocess module. Consider the following example: <subprocess.Popen object at 0x729f0> Here hey is immediately print to stdout of my interpreter, I did not type in the "hey". But I want to read from the output into a string, so I do
1
7848
by: abolduc | last post by:
I have had an underwhelming amount of success hunting down the source of this error and am hoping that someone here may have some insight. Error logged in the event log: Source: MSSQLSERVER Category: (2) EVENT ID: 17887 Description: IO Completion Listener (0x754) Worker 0x00FEC0E8 appears to be non-yielding on Node 1. Approx CPU Used: kernel 0 ms, user 0 ms, Interval: 15187.
0
9865
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
9706
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10667
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
10303
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9446
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
7848
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
7025
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5880
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3140
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.