Re: If or while looping
From: Paul G. Tobey [eMVP] (ptobey)
Date: 11/04/04
- Next message: Paul G. Tobey [eMVP]: "Re: creating a file browser"
- Previous message: frakk: "evc++ dotmatrix print"
- In reply to: Plaw: "Re: If or while looping"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 4 Nov 2004 08:37:34 -0700
I don't understand what the goal is. Why do you need to know the exact
moment of exit of the other application. What happens then?
1) If you really need to know the moment the other process exits, but you
want to maintain control over the UI of the launching application, you'd
have to do the launch/wait in a separate thread. Button1 would look
something roughly like this:
{
// You need to keep this handle for later, in case the user exits your
application
// before the other application.
HANDLE hth = CreateThread( ... );
}
The thread procedure would look something roughly like this:
{
// Launch the other process.
HANDLE hproc = CreateProcess( ... );
// Create a named event that our program will fire if we need to get out
// of this thread early.
HANDLE exitEv = CreateEvent( ... );
// List of handles to wait on.
HANDLE wait[] = { hproc, exitEv };
DWORD res = WaitForMultipleObjects( wait, sizeof( wait ) / sizoef(
wait[ 0 ] ), FALSE,
INFINITE );
switch( res )
{
case WAIT_OBJECT_0: // The other process exited. Do whatever!
break;
default: // Either something is very
wrong or it's time to exit the
// thread early.
break;
}
CloseHandle( exitEv );
CloseHandle( hproc ); // Note that this does *not* terminate the
other process.
}
To exit the launched application, read the newsgroup archives on "terminate
application createprocess" and I think you'll see that you need to do a fair
amount of work to perform that operation cleanly without losing resources.
http://groups.google.com/groups?hl=en&group=microsoft.public.windowsce
Paul T.
"Plaw" <Plaw@discussions.microsoft.com> wrote in message
news:3972E7F1-46F2-4640-93A3-B3317DA20C51@microsoft.com...
> Got it, now onto the next part..
>
> explorer.exe is not the app i watch to launch.. its an example..
> The code is doing exactly like you said, launching within 10 seconds, when
> I
> exit it restarts the app and the launcher remains frozen..
>
> 1) how would i make it so it doesnt freeze
> 2) the second button I am working on is to kill the process that was
> created
> when i need to exit..
>
> Thanks again
>
>
> void CLauncherDlg::OnButton1()
>
> {
>
> Sleep(8000);
> PROCESS_INFORMATION pi;
>
> ::CreateProcess(TEXT("\\Windows\\explorer.exe"),NULL ,NULL, NULL, FALSE,
> 0,
> NULL, NULL, NULL, &pi);
>
>
> while (::WaitForSingleObject(pi.hProcess, INFINITE) == 0 )
> {
> ::CreateProcess(TEXT("\\Windows\\explorer.exe"),NULL ,NULL, NULL,
> FALSE,
> 0,
> NULL, NULL, NULL, &pi);
> }
>
> }
>
>
> void CLauncherDlg::OnButton2()
> {
> PROCESS_INFORMATION pi;
> CloseHandle(pi.hProcess);
> }
>
> "Paul G. Tobey [eMVP]" wrote:
>
>> Read the help. WaitForSingleObject does not return until the process
>> handle
>> is signaled, meaning that the process has exited.
>>
>> Paul T.
>>
>> "Plaw" <Plaw@discussions.microsoft.com> wrote in message
>> news:799CA794-8EDA-44B2-BE3B-7A9ECF063E73@microsoft.com...
>> >I just picked up C++ last week.. with that said..
>> >
>> > You mean something like
>> >
>> > While (::WaitForSingleObject(pi.hProcess, INFINITE))
>> > {
>> > do ????
>> >
>> > "Paul G. Tobey [eMVP]" wrote:
>> >
>> >> OK, so use the process handle returned by CreateProcess in a call to
>> >> WaitForSingleObject and, when the wait returns, the other process has
>> >> exited... Don't forget that the first program's UI will be
>> >> essentially
>> >> locked-up, the way you've written the code, while the other program
>> >> runs.
>> >>
>> >> Paul T.
>> >>
>> >> "Plaw" <Plaw@discussions.microsoft.com> wrote in message
>> >> news:C969D05D-F1A3-4907-9942-5599DB625980@microsoft.com...
>> >> >I am trying to create a simple application that will launch another
>> >> > application 10 seconds after it starts, then wait till that app
>> >> > closes
>> >> > and
>> >> > start it up again.
>> >> >
>> >> > I need it in a loop till i kill the parent application.
>> >> >
>> >> > void CLauncherDlg::OnButton1()
>> >> >
>> >> > {
>> >> > Sleep(8000);
>> >> > PROCESS_INFORMATION pi;
>> >> >
>> >> > ::CreateProcess(TEXT("\\Windows\\Explorer.exe"),NULL ,NULL, NULL,
>> >> > FALSE,
>> >> > 0,
>> >> > NULL, NULL, NULL, &pi);
>> >> >
>> >> > }
>> >> >
>> >> > And that is where I am at.. Any help would be greatly appreciated.
>> >> >
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>>
>>
>>
- Next message: Paul G. Tobey [eMVP]: "Re: creating a file browser"
- Previous message: frakk: "evc++ dotmatrix print"
- In reply to: Plaw: "Re: If or while looping"
- Messages sorted by: [ date ] [ thread ]