winapi - RegisterApplicationRestart with different path -


i have 2 applications. both of them use same resources. lets call these resources "profile resources". application b cannot started until application shutsdown. have app running , trying shut down, launch app b path. explored registerapplicationrestart not accomplish it. possible done? i'm getting stuck @ point application shutdown, cant run code launch app b.

a can launch b using createprocess() before exiting, passing own process handle b. before b accesses resource, can wait on a's handle using waitforsingleobject() or related function. when handle signaled, a has terminated, b can close handle using closehandle() , move on needed.

to pass a's process handle b, a can either:

  1. open own process handle using openprocess() getcurrentprocessid() process id, mark handle inheritable using sethandleinformation(), , pass handle value b command-line parameter, setting binherithandles parameter of createprocess() true.

  2. run b first , have create ipc listener (named pipe, mailslot, socket, etc), a can duplicate own process handle b's use via duplicatehandle() getcurrentprocess() source handle , b's process handle (from createprocess()) target process, send duplicate handle value b via ipc.

a simpler technique have a pass own process id, rather process handle, b command-line parameter, b can use openprocess() open a's process handle. although work, have small race condition - before b has chance open process handle, a might terminate , os reuse process id new unrelated process, b handle to, , wait on, wrong process.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -