c# - Wait on thread that creates an instance that creates a thread -
let me paint situation:
i have wcf server creates thread. thread executes assembly, lets call abc.exe. abc.exe this:
static void main(string[] args) { objclientbase.onhandshakecompleted += new eventhandler(objclientbase_onhandshakecompleted); objclientbase.onshutdowninitiated += new eventhandler(objclientbase_onshutdowninitiated); objclientbase.connect(); objoeemon = new main(); system.threading.thread.sleep(system.threading.timeout.infinite); } where connect does:
objclientthread = new thread(start) { isbackground = true }; objclientthread.start(); and start
/// <summary> /// starts client program. /// </summary> private void start() { //we open proxy let connections happen objproxy.open(); if (performhandshake()) { isconnected = true; delayedshutdownbool = false; //while connected, thread keeps client alive while (isconnected) { system.threading.thread.sleep(500); if (delayedshutdownbool) { system.threading.thread.sleep(500); objproxy.close(); objconfiguration = null; isconnected = false; } } } } this abc.exe client connects server wcf.
so instead of having sleep(infinite) want use manualresetevents (or other thing) main() gets notified end of thread connect makes , end execution too. don't know how main can notified, because calling function of instance creates thread.
what don't want active wait there while(condition) sleep
my fault...i passing new instance of class instead of current one, callback done instance , variables modified not correct ones.
works perfect now. answers, helped me think sequence think error.
Comments
Post a Comment