473,418 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

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 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
12 2343
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
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)...
4
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....
6
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...
2
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...
2
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...
13
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...
1
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...
0
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...
0
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...

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.