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

Waiting of process completion

P: n/a
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 processRebuildAW As Process

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

ClearListBox()

ClearProgressBar()

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

Do While Not (processRebuildAW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

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

processRebuildAW = Process.Start(strPath)

End Sub

End Class

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


Nov 20 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
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.faa.gov> wrote in message
news:%2***************@tk2msftngp13.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 processRebuildAW As Process

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

ClearListBox()

ClearProgressBar()

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

Do While Not (processRebuildAW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

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

processRebuildAW = Process.Start(strPath)

End Sub

End Class

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

Nov 20 '05 #2

P: n/a
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.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
///
Nov 20 '05 #3

P: n/a
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 processRebuildAW As Process
Delegate Sub AsyncRebuildAW()

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

ClearListBox()

ClearProgressBar()

#If Not Debug Then

If chkRebuildAW.Checked = True Then

Dim objAsync As New AsyncRebuildAW(AddressOf RebuildAWPath)

Dim objResult As IAsyncResult = objAsync.BeginInvoke(Nothing, Nothing)

Do Until objResult.IsCompleted

Loop

objAsync.EndInvoke(objResult)

End If
#End If

lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

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

processRebuildAW = Process.Start(strPath)

End Sub

End Class

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

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.faa.gov> wrote in message
news:%2***************@tk2msftngp13.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 processRebuildAW As Process

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

ClearListBox()

ClearProgressBar()

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

Do While Not (processRebuildAW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.StartupPath & "\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)

End Sub

End Class

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


Nov 20 '05 #4

P: n/a
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**************@TK2MSFTNGP11.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.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
///

Nov 20 '05 #5

P: n/a
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****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.faa.gov> wrote in message
news:%2***************@tk2msftngp13.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 processRebuildAW As Process

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

ClearListBox()

ClearProgressBar()

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

Do While Not (processRebuildAW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.StartupPath & "\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)

End Sub

End Class

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


Nov 20 '05 #6

P: n/a
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.messaging
namespace

asyncR = ctype(ar, AsyncResult)

dim asyncDel as AsyncRebuildAW

asyncDel = Ctype(asyncR.AsyncDelegate, AsyncrebuildAw)

asyncDel.EndInvoke(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.faa.gov> wrote in message
news:uj**************@TK2MSFTNGP12.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 processRebuildAW As Process
Delegate Sub AsyncRebuildAW()

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

ClearListBox()

ClearProgressBar()

#If Not Debug Then

If chkRebuildAW.Checked = True Then

Dim objAsync As New AsyncRebuildAW(AddressOf RebuildAWPath)

Dim objResult As IAsyncResult = objAsync.BeginInvoke(Nothing, Nothing)

Do Until objResult.IsCompleted

Loop

objAsync.EndInvoke(objResult)

End If
#End If

lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.StartupPath & "\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)

End Sub

End Class

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

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.faa.gov> wrote in message news:%2***************@tk2msftngp13.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 processRebuildAW As Process

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

ClearListBox()

ClearProgressBar()

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

Do While Not (processRebuildAW.HasExited)

' RIGHT HERE IS MY PROBLEM

Loop

#End If

lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.StartupPath &

"\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)

End Sub

End Class

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



Nov 20 '05 #7

P: n/a
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 processRebuildAW As Process
Delegate Sub AsyncRebuildAW()

Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCreate.Click
ClearListBox()
ClearProgressBar()
If chkRebuildAW.Checked = True Then
Dim objAsync As New AsyncRebuildAW(AddressOf RebuildAWPath)
Dim objCB As New AsyncCallback(AddressOf callbackmethod)
Dim objAR As IAsyncResult
objAR = objAsync.BeginInvoke(Nothing, objCB)
End If
End Sub

Private Sub RebuildAWPath()
Dim strPath As String = Application.StartupPath &
"\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)
End Sub

Private Sub callbackmethod(ByVal ar As IAsyncResult)
Dim asyncR As System.runtime.remoting.messaging.AsyncResult ' this
is in System.runtime.remoting.messaging namespace
asyncR = CType(ar, System.runtime.remoting.messaging.AsyncResult)
Dim asyncDel As AsyncRebuildAW
asyncDel = CType(asyncR.AsyncDelegate, AsyncRebuildAW)
asyncDel.EndInvoke(ar)

' *********************************************
' *** NOTHING BELOW IS BEING EXECUTED.
' *********************************************
Dim itemChecked As Object
Dim strCheckedFile As String
Dim strMovedFile As String
For Each itemChecked In clbFiles.CheckedItems
strCheckedFile = itemChecked.ToString()
If InStr(strCheckedFile, txtACRADirectory.Text) > 0 Then
strMovedFile = Replace(strCheckedFile,
txtACRADirectory.Text, txtMergeDirectory.Text)
ElseIf InStr(strCheckedFile, txtAWDirectory.Text) > 0 Then
strMovedFile = Replace(strCheckedFile,
txtAWDirectory.Text, txtMergeDirectory.Text)
Else
strMovedFile = strCheckedFile
End If
lstFiles.Items.Add(strMovedFile)
Next
lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
If lstFiles.Items.Count > 0 Then
btnWebsite.Enabled = True
Else
btnWebsite.Enabled = False
End If
lstFiles.Sorted = True
End Sub

End Class

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.messaging namespace

asyncR = ctype(ar, AsyncResult)

dim asyncDel as AsyncRebuildAW

asyncDel = Ctype(asyncR.AsyncDelegate, AsyncrebuildAw)

asyncDel.EndInvoke(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.faa.gov> wrote in message
news:uj**************@TK2MSFTNGP12.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 processRebuildAW As Process
Delegate Sub AsyncRebuildAW()

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

ClearListBox()

ClearProgressBar()

#If Not Debug Then

If chkRebuildAW.Checked = True Then

Dim objAsync As New AsyncRebuildAW(AddressOf RebuildAWPath)

Dim objResult As IAsyncResult = objAsync.BeginInvoke(Nothing, Nothing)

Do Until objResult.IsCompleted

Loop

objAsync.EndInvoke(objResult)

End If
#End If

lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.StartupPath &

"\rebuildawpath.bat"

processRebuildAW = Process.Start(strPath)

End Sub

End Class

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

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.faa.gov> wrote in message news:%2***************@tk2msftngp13.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 processRebuildAW As Process
>
> Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e

As > System.EventArgs) Handles btnCreate.Click
>
> ClearListBox()
>
> ClearProgressBar()
>
> #If Not Debug Then
> IF chkRebuildAW.Checked = True Then RebuildAWPath()
>
> Do While Not (processRebuildAW.HasExited)
>
> ' RIGHT HERE IS MY PROBLEM
>
> Loop
>
>
>
> #End If
>
> lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
>
> blah blah blah more code more code more code
>
> End Sub
>
> Private Sub RebuildAWPath()
>
> Dim strPath As String = Application.StartupPath &

"\rebuildawpath.bat"
>
> processRebuildAW = Process.Start(strPath)
>
> End Sub
>
> End Class
>
> **********************************************
>
>
>
>



Nov 20 '05 #8

P: n/a
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.HasExited
... 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.faa.gov> wrote in message
news:uh**************@TK2MSFTNGP09.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 processRebuildAW As Process
Delegate Sub AsyncRebuildAW()

Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCreate.Click
ClearListBox()
ClearProgressBar()
If chkRebuildAW.Checked = True Then
Dim objAsync As New AsyncRebuildAW(AddressOf RebuildAWPath) Dim objCB As New AsyncCallback(AddressOf callbackmethod)
Dim objAR As IAsyncResult
objAR = objAsync.BeginInvoke(Nothing, objCB)
End If
End Sub

Private Sub RebuildAWPath()
Dim strPath As String = Application.StartupPath &
"\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)
End Sub

Private Sub callbackmethod(ByVal ar As IAsyncResult)
Dim asyncR As System.runtime.remoting.messaging.AsyncResult ' this
is in System.runtime.remoting.messaging namespace
asyncR = CType(ar, System.runtime.remoting.messaging.AsyncResult)
Dim asyncDel As AsyncRebuildAW
asyncDel = CType(asyncR.AsyncDelegate, AsyncRebuildAW)
asyncDel.EndInvoke(ar)

' *********************************************
' *** NOTHING BELOW IS BEING EXECUTED.
' *********************************************
Dim itemChecked As Object
Dim strCheckedFile As String
Dim strMovedFile As String
For Each itemChecked In clbFiles.CheckedItems
strCheckedFile = itemChecked.ToString()
If InStr(strCheckedFile, txtACRADirectory.Text) > 0 Then
strMovedFile = Replace(strCheckedFile,
txtACRADirectory.Text, txtMergeDirectory.Text)
ElseIf InStr(strCheckedFile, txtAWDirectory.Text) > 0 Then
strMovedFile = Replace(strCheckedFile,
txtAWDirectory.Text, txtMergeDirectory.Text)
Else
strMovedFile = strCheckedFile
End If
lstFiles.Items.Add(strMovedFile)
Next
lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
If lstFiles.Items.Count > 0 Then
btnWebsite.Enabled = True
Else
btnWebsite.Enabled = False
End If
lstFiles.Sorted = True
End Sub

End Class

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.messaging
namespace

asyncR = ctype(ar, AsyncResult)

dim asyncDel as AsyncRebuildAW

asyncDel = Ctype(asyncR.AsyncDelegate, AsyncrebuildAw)

asyncDel.EndInvoke(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.faa.gov> wrote in message news:uj**************@TK2MSFTNGP12.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 processRebuildAW As Process
Delegate Sub AsyncRebuildAW()

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

ClearListBox()

ClearProgressBar()

#If Not Debug Then

If chkRebuildAW.Checked = True Then

Dim objAsync As New AsyncRebuildAW(AddressOf RebuildAWPath)

Dim objResult As IAsyncResult = objAsync.BeginInvoke(Nothing, Nothing)

Do Until objResult.IsCompleted

Loop

objAsync.EndInvoke(objResult)

End If
#End If

lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)

blah blah blah more code more code more code

End Sub

Private Sub RebuildAWPath()

Dim strPath As String = Application.StartupPath &

"\rebuildawpath.bat"

processRebuildAW = Process.Start(strPath)

End Sub

End Class

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

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.faa.gov> wrote in

message
> news:%2***************@tk2msftngp13.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 processRebuildAW As Process
> >
> > Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e

As > > System.EventArgs) Handles btnCreate.Click
> >
> > ClearListBox()
> >
> > ClearProgressBar()
> >
> > #If Not Debug Then
> > IF chkRebuildAW.Checked = True Then RebuildAWPath()
> >
> > Do While Not (processRebuildAW.HasExited)
> >
> > ' RIGHT HERE IS MY PROBLEM
> >
> > Loop
> >
> >
> >
> > #End If
> >
> > lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
> >
> > blah blah blah more code more code more code
> >
> > End Sub
> >
> > Private Sub RebuildAWPath()
> >
> > Dim strPath As String = Application.StartupPath &
"\rebuildawpath.bat"
> >
> > processRebuildAW = Process.Start(strPath)
> >
> > End Sub
> >
> > End Class
> >
> > **********************************************
> >
> >
> >
> >
>
>



Nov 20 '05 #9

P: n/a
CJ,

Thanks for all your help. I took out all the delegate stuff and just
inserted:
do while not (processRebuildAW.HasExited)
System.Threading.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****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.HasExited
... 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.faa.gov> wrote in message
news:uh**************@TK2MSFTNGP09.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 processRebuildAW As Process
Delegate Sub AsyncRebuildAW()

Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCreate.Click
ClearListBox()
ClearProgressBar()
If chkRebuildAW.Checked = True Then
Dim objAsync As New AsyncRebuildAW(AddressOf

RebuildAWPath)
Dim objCB As New AsyncCallback(AddressOf callbackmethod)
Dim objAR As IAsyncResult
objAR = objAsync.BeginInvoke(Nothing, objCB)
End If
End Sub

Private Sub RebuildAWPath()
Dim strPath As String = Application.StartupPath &
"\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)
End Sub

Private Sub callbackmethod(ByVal ar As IAsyncResult)
Dim asyncR As System.runtime.remoting.messaging.AsyncResult ' this is in System.runtime.remoting.messaging namespace
asyncR = CType(ar, System.runtime.remoting.messaging.AsyncResult) Dim asyncDel As AsyncRebuildAW
asyncDel = CType(asyncR.AsyncDelegate, AsyncRebuildAW)
asyncDel.EndInvoke(ar)

' *********************************************
' *** NOTHING BELOW IS BEING EXECUTED.
' *********************************************
Dim itemChecked As Object
Dim strCheckedFile As String
Dim strMovedFile As String
For Each itemChecked In clbFiles.CheckedItems
strCheckedFile = itemChecked.ToString()
If InStr(strCheckedFile, txtACRADirectory.Text) > 0 Then
strMovedFile = Replace(strCheckedFile,
txtACRADirectory.Text, txtMergeDirectory.Text)
ElseIf InStr(strCheckedFile, txtAWDirectory.Text) > 0 Then strMovedFile = Replace(strCheckedFile,
txtAWDirectory.Text, txtMergeDirectory.Text)
Else
strMovedFile = strCheckedFile
End If
lstFiles.Items.Add(strMovedFile)
Next
lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
If lstFiles.Items.Count > 0 Then
btnWebsite.Enabled = True
Else
btnWebsite.Enabled = False
End If
lstFiles.Sorted = True
End Sub

End Class

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.messaging
namespace

asyncR = ctype(ar, AsyncResult)

dim asyncDel as AsyncRebuildAW

asyncDel = Ctype(asyncR.AsyncDelegate, AsyncrebuildAw)

asyncDel.EndInvoke(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.faa.gov> wrote in message news:uj**************@TK2MSFTNGP12.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 processRebuildAW As Process
> Delegate Sub AsyncRebuildAW()
>
> Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e
As > System.EventArgs) Handles btnCreate.Click
>
> ClearListBox()
>
> ClearProgressBar()
>
> #If Not Debug Then
>
> If chkRebuildAW.Checked = True Then
>
> Dim objAsync As New AsyncRebuildAW(AddressOf RebuildAWPath)
>
> Dim objResult As IAsyncResult = objAsync.BeginInvoke(Nothing, Nothing) >
> Do Until objResult.IsCompleted
>
> Loop
>
> objAsync.EndInvoke(objResult)
>
> End If
>
>
> #End If
>
> lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
>
> blah blah blah more code more code more code
>
> End Sub
>
> Private Sub RebuildAWPath()
>
> Dim strPath As String = Application.StartupPath &
"\rebuildawpath.bat"
>
> processRebuildAW = Process.Start(strPath)
>
> End Sub
>
> End Class
>
> **********************************************
>
> "CJ Taylor" <no****@blowgoats.com> wrote in message
> news:10*************@corp.supernews.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.faa.gov> wrote in
message
> > news:%2***************@tk2msftngp13.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 processRebuildAW As Process
> > >
> > > Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal

e As
> > > System.EventArgs) Handles btnCreate.Click
> > >
> > > ClearListBox()
> > >
> > > ClearProgressBar()
> > >
> > > #If Not Debug Then
> > > IF chkRebuildAW.Checked = True Then RebuildAWPath()
> > >
> > > Do While Not (processRebuildAW.HasExited)
> > >
> > > ' RIGHT HERE IS MY PROBLEM
> > >
> > > Loop
> > >
> > >
> > >
> > > #End If
> > >
> > > lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
> > >
> > > blah blah blah more code more code more code
> > >
> > > End Sub
> > >
> > > Private Sub RebuildAWPath()
> > >
> > > Dim strPath As String = Application.StartupPath &
> "\rebuildawpath.bat"
> > >
> > > processRebuildAW = Process.Start(strPath)
> > >
> > > End Sub
> > >
> > > End Class
> > >
> > > **********************************************
> > >
> > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #10

P: n/a
Cor
Hi Raymond,

I do not understand this about resources, what happens in my idea is that
the process start and the program nicely waits for the end that is sended to
the console. I did copied this from a program, but even that stringbuilder
that was in is unnecessary if you are sure that there is no output to the
console.
\\\
p.Start()
Dim sr As IO.StreamReader = p.StandardOutput
Dim input As Integer = sr.Read
Do Until input = -1
input = sr.Read
Loop
///
Cor


Nov 20 '05 #11

P: n/a
Raymond,

Hey, as long as it works right? By doing that, you don't have true async
stuff going on, but it will work for now. its a simple fix.. This should
be all you need

Private Sub RebuildAWPath()
Dim strPath As String = Application.StartupPath &
"\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)

'''-----------------inserted

do while not (processRebuildAW.HasExited)
System.Threading.Thread.Sleep(1500)
loop
End Sub
this will keep that background thread that is actually monitoring the
process alive and prevent the callback method from being invoked.

then when .HasExited is true, the method is invoked. which you could do
your completed processing after that.

As for being a help, not a problem. I'm pretty impressed that a DBA has
this much .NET knowledge. No offesne or anything, but a lot of dba's I meet
just want to do there sql/oracle and call it a day. (a few postgres guys in
there too.)

I've been doing .NET for about 2 years now, and I still learn new stuff
every day from it, maybe not in the language constructs themselves, but in
how to handle situations. These groups are great for it.

Anyways, thanks for the advice on faa, and if you need to contact me at
home, please feel free with questions.

my address is cege at tavayn dot no spam com

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:e%****************@tk2msftngp13.phx.gbl...
CJ,

Thanks for all your help. I took out all the delegate stuff and just
inserted:
do while not (processRebuildAW.HasExited)
System.Threading.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****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.HasExited
... 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.faa.gov> wrote in message news:uh**************@TK2MSFTNGP09.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 processRebuildAW As Process
Delegate Sub AsyncRebuildAW()

Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCreate.Click
ClearListBox()
ClearProgressBar()
If chkRebuildAW.Checked = True Then
Dim objAsync As New AsyncRebuildAW(AddressOf

RebuildAWPath)
Dim objCB As New AsyncCallback(AddressOf callbackmethod) Dim objAR As IAsyncResult
objAR = objAsync.BeginInvoke(Nothing, objCB)
End If
End Sub

Private Sub RebuildAWPath()
Dim strPath As String = Application.StartupPath &
"\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)
End Sub

Private Sub callbackmethod(ByVal ar As IAsyncResult)
Dim asyncR As System.runtime.remoting.messaging.AsyncResult ' this is in System.runtime.remoting.messaging namespace
asyncR = CType(ar, System.runtime.remoting.messaging.AsyncResult) Dim asyncDel As AsyncRebuildAW
asyncDel = CType(asyncR.AsyncDelegate, AsyncRebuildAW)
asyncDel.EndInvoke(ar)

' *********************************************
' *** NOTHING BELOW IS BEING EXECUTED.
' *********************************************
Dim itemChecked As Object
Dim strCheckedFile As String
Dim strMovedFile As String
For Each itemChecked In clbFiles.CheckedItems
strCheckedFile = itemChecked.ToString()
If InStr(strCheckedFile, txtACRADirectory.Text) > 0 Then strMovedFile = Replace(strCheckedFile,
txtACRADirectory.Text, txtMergeDirectory.Text)
ElseIf InStr(strCheckedFile, txtAWDirectory.Text) > 0 Then strMovedFile = Replace(strCheckedFile,
txtAWDirectory.Text, txtMergeDirectory.Text)
Else
strMovedFile = strCheckedFile
End If
lstFiles.Items.Add(strMovedFile)
Next
lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
If lstFiles.Items.Count > 0 Then
btnWebsite.Enabled = True
Else
btnWebsite.Enabled = False
End If
lstFiles.Sorted = True
End Sub

End Class

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.messaging
> namespace
>
> asyncR = ctype(ar, AsyncResult)
>
> dim asyncDel as AsyncRebuildAW
>
> asyncDel = Ctype(asyncR.AsyncDelegate, AsyncrebuildAw)
>
> asyncDel.EndInvoke(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.faa.gov> wrote in

message
> news:uj**************@TK2MSFTNGP12.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 processRebuildAW As Process
> > Delegate Sub AsyncRebuildAW()
> >
> > Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal
e As > > System.EventArgs) Handles btnCreate.Click
> >
> > ClearListBox()
> >
> > ClearProgressBar()
> >
> > #If Not Debug Then
> >
> > If chkRebuildAW.Checked = True Then
> >
> > Dim objAsync As New AsyncRebuildAW(AddressOf RebuildAWPath)
> >
> > Dim objResult As IAsyncResult = objAsync.BeginInvoke(Nothing, Nothing) > >
> > Do Until objResult.IsCompleted
> >
> > Loop
> >
> > objAsync.EndInvoke(objResult)
> >
> > End If
> >
> >
> > #End If
> >
> > lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
> >
> > blah blah blah more code more code more code
> >
> > End Sub
> >
> > Private Sub RebuildAWPath()
> >
> > Dim strPath As String = Application.StartupPath &
> "\rebuildawpath.bat"
> >
> > processRebuildAW = Process.Start(strPath)
> >
> > End Sub
> >
> > End Class
> >
> > **********************************************
> >
> > "CJ Taylor" <no****@blowgoats.com> wrote in message
> > news:10*************@corp.supernews.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.faa.gov> wrote
in > message
> > > news:%2***************@tk2msftngp13.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 processRebuildAW As Process
> > > >
> > > > Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As
> > > > System.EventArgs) Handles btnCreate.Click
> > > >
> > > > ClearListBox()
> > > >
> > > > ClearProgressBar()
> > > >
> > > > #If Not Debug Then
> > > > IF chkRebuildAW.Checked = True Then RebuildAWPath()
> > > >
> > > > Do While Not (processRebuildAW.HasExited)
> > > >
> > > > ' RIGHT HERE IS MY PROBLEM
> > > >
> > > > Loop
> > > >
> > > >
> > > >
> > > > #End If
> > > >
> > > > lblReadyCount.Text =

Convert.ToString(lstFiles.Items.Count) > > > >
> > > > blah blah blah more code more code more code
> > > >
> > > > End Sub
> > > >
> > > > Private Sub RebuildAWPath()
> > > >
> > > > Dim strPath As String = Application.StartupPath &
> > "\rebuildawpath.bat"
> > > >
> > > > processRebuildAW = Process.Start(strPath)
> > > >
> > > > End Sub
> > > >
> > > > End Class
> > > >
> > > > **********************************************
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #12

P: n/a
Raymond,

Hey, as long as it works right? By doing that, you don't have true async
stuff going on, but it will work for now. its a simple fix.. This should
be all you need

Private Sub RebuildAWPath()
Dim strPath As String = Application.StartupPath &
"\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)

'''-----------------inserted

do while not (processRebuildAW.HasExited)
System.Threading.Thread.Sleep(1500)
loop
End Sub
this will keep that background thread that is actually monitoring the
process alive and prevent the callback method from being invoked.

then when .HasExited is true, the method is invoked. which you could do
your completed processing after that.

As for being a help, not a problem. I'm pretty impressed that a DBA has
this much .NET knowledge. No offesne or anything, but a lot of dba's I meet
just want to do there sql/oracle and call it a day. (a few postgres guys in
there too.)

I've been doing .NET for about 2 years now, and I still learn new stuff
every day from it, maybe not in the language constructs themselves, but in
how to handle situations. These groups are great for it.

Anyways, thanks for the advice on faa, and if you need to contact me at
home, please feel free with questions.

my address is cege at tavayn dot no spam com

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:e%****************@tk2msftngp13.phx.gbl...
CJ,

Thanks for all your help. I took out all the delegate stuff and just
inserted:
do while not (processRebuildAW.HasExited)
System.Threading.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****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.HasExited
... 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.faa.gov> wrote in message news:uh**************@TK2MSFTNGP09.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 processRebuildAW As Process
Delegate Sub AsyncRebuildAW()

Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCreate.Click
ClearListBox()
ClearProgressBar()
If chkRebuildAW.Checked = True Then
Dim objAsync As New AsyncRebuildAW(AddressOf

RebuildAWPath)
Dim objCB As New AsyncCallback(AddressOf callbackmethod) Dim objAR As IAsyncResult
objAR = objAsync.BeginInvoke(Nothing, objCB)
End If
End Sub

Private Sub RebuildAWPath()
Dim strPath As String = Application.StartupPath &
"\rebuildawpath.bat"
processRebuildAW = Process.Start(strPath)
End Sub

Private Sub callbackmethod(ByVal ar As IAsyncResult)
Dim asyncR As System.runtime.remoting.messaging.AsyncResult ' this is in System.runtime.remoting.messaging namespace
asyncR = CType(ar, System.runtime.remoting.messaging.AsyncResult) Dim asyncDel As AsyncRebuildAW
asyncDel = CType(asyncR.AsyncDelegate, AsyncRebuildAW)
asyncDel.EndInvoke(ar)

' *********************************************
' *** NOTHING BELOW IS BEING EXECUTED.
' *********************************************
Dim itemChecked As Object
Dim strCheckedFile As String
Dim strMovedFile As String
For Each itemChecked In clbFiles.CheckedItems
strCheckedFile = itemChecked.ToString()
If InStr(strCheckedFile, txtACRADirectory.Text) > 0 Then strMovedFile = Replace(strCheckedFile,
txtACRADirectory.Text, txtMergeDirectory.Text)
ElseIf InStr(strCheckedFile, txtAWDirectory.Text) > 0 Then strMovedFile = Replace(strCheckedFile,
txtAWDirectory.Text, txtMergeDirectory.Text)
Else
strMovedFile = strCheckedFile
End If
lstFiles.Items.Add(strMovedFile)
Next
lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
If lstFiles.Items.Count > 0 Then
btnWebsite.Enabled = True
Else
btnWebsite.Enabled = False
End If
lstFiles.Sorted = True
End Sub

End Class

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.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.messaging
> namespace
>
> asyncR = ctype(ar, AsyncResult)
>
> dim asyncDel as AsyncRebuildAW
>
> asyncDel = Ctype(asyncR.AsyncDelegate, AsyncrebuildAw)
>
> asyncDel.EndInvoke(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.faa.gov> wrote in

message
> news:uj**************@TK2MSFTNGP12.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 processRebuildAW As Process
> > Delegate Sub AsyncRebuildAW()
> >
> > Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal
e As > > System.EventArgs) Handles btnCreate.Click
> >
> > ClearListBox()
> >
> > ClearProgressBar()
> >
> > #If Not Debug Then
> >
> > If chkRebuildAW.Checked = True Then
> >
> > Dim objAsync As New AsyncRebuildAW(AddressOf RebuildAWPath)
> >
> > Dim objResult As IAsyncResult = objAsync.BeginInvoke(Nothing, Nothing) > >
> > Do Until objResult.IsCompleted
> >
> > Loop
> >
> > objAsync.EndInvoke(objResult)
> >
> > End If
> >
> >
> > #End If
> >
> > lblReadyCount.Text = Convert.ToString(lstFiles.Items.Count)
> >
> > blah blah blah more code more code more code
> >
> > End Sub
> >
> > Private Sub RebuildAWPath()
> >
> > Dim strPath As String = Application.StartupPath &
> "\rebuildawpath.bat"
> >
> > processRebuildAW = Process.Start(strPath)
> >
> > End Sub
> >
> > End Class
> >
> > **********************************************
> >
> > "CJ Taylor" <no****@blowgoats.com> wrote in message
> > news:10*************@corp.supernews.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.faa.gov> wrote
in > message
> > > news:%2***************@tk2msftngp13.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 processRebuildAW As Process
> > > >
> > > > Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As
> > > > System.EventArgs) Handles btnCreate.Click
> > > >
> > > > ClearListBox()
> > > >
> > > > ClearProgressBar()
> > > >
> > > > #If Not Debug Then
> > > > IF chkRebuildAW.Checked = True Then RebuildAWPath()
> > > >
> > > > Do While Not (processRebuildAW.HasExited)
> > > >
> > > > ' RIGHT HERE IS MY PROBLEM
> > > >
> > > > Loop
> > > >
> > > >
> > > >
> > > > #End If
> > > >
> > > > lblReadyCount.Text =

Convert.ToString(lstFiles.Items.Count) > > > >
> > > > blah blah blah more code more code more code
> > > >
> > > > End Sub
> > > >
> > > > Private Sub RebuildAWPath()
> > > >
> > > > Dim strPath As String = Application.StartupPath &
> > "\rebuildawpath.bat"
> > > >
> > > > processRebuildAW = Process.Start(strPath)
> > > >
> > > > End Sub
> > > >
> > > > End Class
> > > >
> > > > **********************************************
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.