PDA

Click to See Complete Forum and Search --> : App. still there?


AlexGold
Feb 22nd, 2002, 09:56 AM
Hi,
I have a VB Appl. which connects to a server and runs through a script on this server. It keeps doing this until the server is either shut-down or the script just dies because of a fatal error. No idea how this works, didin't set it up, but it's not important anyway. Now, this VB Appl. keeps on trying to establish a connection to the server, but obviously fails, if the server isn't there. So, basically, the exe just hangs there. Now I've written a C++ exe which will start this VB app as a service with automatic connection. The C++ program keeps on timing the VB app to check if its still there. Well, that doesn't help, I realized, because the VB prog. is still there, it's still responding, it just can't connect. Anybody have a clue, how I can get a reply from the VB exe which will tell me that it's not getting an answer from the server, so I can kill it and restart it? This task is really killing me, I'm not a programming pro, so I've run out of ideas. Thx in advance.

Alex

CornedBee
Feb 23rd, 2002, 10:49 AM
Can't the VB app simply check if it gets a conection and if not terminate? This would eliminate the need for a C++ app.
If you can't change the code of the VB app, you try in vain since there is no built-in mechanism to tell you in what state an app is.

AlexGold
Feb 23rd, 2002, 01:06 PM
That woud be possible, problem is, can it restart after it has terminated? The VB app connects to another server and is sort of a server itself, to which clients connect. So, after it hangs up and terminates, it doesn't restart, clients can't connect, basically the same as letting it just hang. Is it possible to restart the app after it has terminated itself? Ideas? Suggestions? Help? Thx. Alex

CornedBee
Feb 24th, 2002, 04:06 AM
It could create a process then terminate. This process gets the handle of the VB process and waits until it has terminated (WaitForSingleObject). Then it restarts the process and terminates itself.

AlexGold
Feb 25th, 2002, 07:09 AM
Thx CornedBee. I think I get where you're going. The VB app. runs on start up as a process. It terminates itself when the connection fails. Ok, got that. But I don't understand what you mean with :
(WaitForSingleObject). Then it restarts the process and terminates itself.
Do you have an idea how the code would have to look/work? I have never done any work with processes, so I'm really confused at the moment. I wanted to get the process id of the vb app, but I only get the id of the c++ app. I figured out why, but maybe you get the picture, I'm not really that comfy with c++:-)
Thx again.
Alex

CornedBee
Feb 25th, 2002, 10:00 AM
It's a little bit complicated. You basically create the new process with CreateProcess. Then you need to obtain a handle to your own process via GetCurrentProcess and duplicate it for the other process via DuplicateHandle. Meanwhile the other process creates a global event object and waits for it. The VB app writes the duplicated handle to a file, then opens the event object, signals it (the other process can resume execution) and then terminates. The other process reads the process handle from the file, uses it to wait until the VB app has finished, closes the handle, creates the VB app again and then terminates.

You're gonna learn a lot by this ;)