Sunday, 15 June 2014

vb.net - Simplest method for passing flag between two separate .net processes -



vb.net - Simplest method for passing flag between two separate .net processes -

i have 2 separate vb.net applications. 1 gui frontend winform , other console application handles file transfers , runs in background. file transfer application monitors directory , when new files found, transfers files destination. checks remote destination accessible. have flag indicates file transfer task can connect remote destination , display status on gui.

example of how gui application starts file transfer console application:

public filexferprocess process dim startinfo new processstartinfo("filexfer.exe") startinfo.createnowindow = true startinfo.useshellexecute = false filexferprocess = process.start(startinfo)

i know there many different types of interprocess communication techniques looking simplest solution sharing boolean state.

i ended using mutex pass flag between separate processes. not require overhead , handles if process if abruptly closed (since mutex destroyed task created it).

below code snippets:

in file transfer task

public hmutex_connected mutex ... ' if connected, set mutex hmutex_connected = new mutex(true, "filexfer_connected") ... ' if disconnected, destroy mutex hmutex_connected.close()

in main application gui

public function isconnected() boolean dim bconnected boolean = false seek mutex.openexisting("filexfer_connected") bconnected = true grab ex waithandlecannotbeopenedexception ' "mutex not exist." grab ex unauthorizedaccessexception ' "unauthorized access: " & ex.message grab ex exception ' ex.tostring end seek homecoming bconnected end function

vb.net ipc

No comments:

Post a Comment