Question Process Start Question?

raysefo

Well-known member
Joined
Jul 21, 2010
Messages
207
Programming Experience
Beginner
Hi,

I have two console applications. Lets say A and B. I would like to call B from inside A with parameters. Is there a way to do it?

Thanks in advance.

Best Regards.
 
Thanks for your reply. I used something like this and got "The system cannot find the file specified"
Is there a way to fix this?

Dim psi As ProcessStartInfo = New ProcessStartInfo
psi.FileName = "D:\Profiles\abc\My Documents\Visual Studio 2010\Projects\CurrentMonth\CurrentMonth\bin\Debug\CurrentMoth.exe"
psi.Arguments = contactId.ToString + " 1"

psi.UseShellExecute = True
Dim proc As Process = Process.Start(psi)
proc.WaitForExit()
 
Try moving to a filepath without spaces. The command prompt hates spaces. You could also try enclosing the entire filepath (within the .FileName) in quotes.

"D:\Profiles\abc\My Documents\Visual Studio 2010\Projects\CurrentMonth\CurrentMonth\bin\Debug\ CurrentMoth.exe"

If you still get the error, try looking in the StackTrace, or exception properties, to find the file it was attempting to find or use the debugger and put a breakpoint on the line. I like going Debug>Exceptions> and check off both Common Language Runtime exceptions and Managed Debugging Assistants checkboxes under Thrown heading. Then I get notified before the program crashes if something goes wrong.
 
Thanks for your replies. I have one more question,Can I call this Process within a loop? Here is my sample Process code below;
...
'Call CurrentMonth
Dim psi As ProcessStartInfo = New ProcessStartInfo
psi.FileName = "D:\Profiles\abc\My Documents\Visual Studio 2010\Projects\CurrentMonth\CurrentMonth\bin\Debug\CurrentMonth.exe"
psi.Arguments = contactId.ToString + " 1"
Dim proc As Process = Process.Start(psi)
...

But I guess there is a problem about the process because It only works for once then It halts somehow.

Best Regards.
 
When I try to call Start Process inside a loop, I m getting this error "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."

Any ideas?

Thanks in advance.
 
Hi,

I think It gets this error while trying to open a connection which is already opened?! I mean in console App. A, I opened a connection for doing insert operation and then call this B. Inside of B, I m opening same connection again in order to make update and insert operations. Can this be the problem? If so, how can I share the connection for both of them?

Thanks in advance.

Best Regards.
 
If it were a problem with getting the connection multiple times, don't you think it would never work, as app B would never (not even the first time) be able to open the connection since app A already has it? Just a thought.

Question: is process B exiting before you start the next instance of process B? Based on your snippet I would guess not. You can use the Process.WaitForExit() method to wait for a process to finish executing before you continue and create a new process, which should close the port and let you reopen it in the next process?
 
Hi :)

Concerning the first question ("The system cannot find the file specified"), I think the problem isn't in the spaces in the PATH, but the space between the last "\" and the name of the application: "...\ CurrentMoth.exe".

Now, about the second point: "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."

Well. First, if calling the app only once it works, so, you probably do not have a "server problem".

Have two or more "connections" to a database will lead to problems ONLY if you create the connection in a way that prevents other applications of open the database too. If you are open the database in a "exclusive" mode, than you can have only ONE connection open at a time. But I think that this is not the "default" way to open a database... I usually use "microsoft access" in small apps and never had a problem like this. But... I have an APP that tryes to open a microsoft access database and sometimes it fails, because other application opens it in a esclusive mode. So it's possible.

Another problem coud be the operations in the database, not the connection at all.
If you are trying to read a table or row of table that is locked because other proccess is writing to it (for example), than you can have these types of issues too.

If it's not important that all the proccess that you want to launch run in parallel, you can simple make a call to ".WaitForExit()" after start the proccess. Ex:

VB.NET:
'Call CurrentMonth
Dim objProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
objProcess.StartInfo.FileName = "D:\Profiles\abc\My  Documents\Visual Studio  2010\Projects\CurrentMonth\CurrentMonth\bin\Debug\CurrentMonth.exe"
objProcess.StartInfo.Arguments = contactId.ToString + " 1"
objProcess.Start()
objProcess.WaitForExit()
This will make each proccess be launched only after the last one finished.
Doing this, you will know when the task is finished and is safe to continue to work on the database.

If it's a connection issue and you do not have access to the "CurrentMonth" app, you can use the code above, closing the connection before enter the looping and reopen it when exits the looping.
 
Back
Top