c# - Function waits for response from other app -
we working on integrating 2 different applications run simultaneously , share data. 1 application provides data, other 1 computes values based off external systems , data , has provide first application.
we using library share data between applications: http://grouplab.cpsc.ucalgary.ca/cookbook/index.php/toolkits/networking
the library allows create shared dictionary can queried application (as long knows location of shared dictionary).
so, should happen program has provide data program b , program b uses data , returns other data program a.
my problem how make program wait response b. in more concrete terms, can put object in shared dictionary, other program gets notified of change in dictionary, can compute attribtues , update object in dictionary. program can notified, want program wait till gets response - program a's action should based on returned value.
a ugly way see can done have infinite loop inside function, keeps querying dictionary see if object has been udpated - if has break out of loop , use object , computed attributes. know of nicer solution?
using subscription model, able avoid infinite-looping. why need loop when times need check when updated? since subscribe key patterns in dictionary , connection notified when key fitting pattern updated/added, need check on that.
so basically, can use manualresetevent wait synchronization within own system. here example of usage of manualresetevent:
using system; using system.threading; class program { static void main(string[] args) { // create reset event -- unsignalled var resetevent = new manualresetevent(false); // information filled thread string information = null; // other thread run action infoget = delegate { // information information = console.readline(); // signal event because we're done resetevent.set(); }; // call action in seperate thread infoget.begininvoke(null, null); // wait completion resetevent.waitone(); // write out information console.writeline(information); } }
to translate framework, might have subscription handler check updated, find wait handle , signal it, advancing proper waiting threads.
Comments
Post a Comment