c# - TaskWrapper - threading and delegate confusion -
can explain code me little have firmer grasp of going on in it?
taskwrapper = xtthreadpool.default_pool.run((system.threading.threadstart)delegate() { //remote procedure execution , result processing code. //some vars set in here used after join() below. }, true, true); while (taskwrapper.status == xtthreadpool.task.status.none) { system.threading.thread.sleep(10); } ... taskwrapper.join(); it looks me separate thread being created , remote procedure call used within it. i'm little hazy use of delegate or syntax of taskwrapper object creation though.
well it's little tricky without knowing what's in xtthreadpool class, have guess...
the chances first bit...
taskwrapper = xtthreadpool.default_pool.run((system.threading.threadstart)delegate() { //remote procedure execution , result processing code. //some vars set in here used after join() below. }, true, true); ...starts thread running asynchronously , passes method specified in section you've put comments. achieved creating instance of thread passing method delegate constructor, , calling newthread.start(), starts execution on new thread inside application's thread pool. thread reference can used check status of thread , see if it's completed or not, section does:
while (taskwrapper.status == xtthreadpool.task.status.none) { system.threading.thread.sleep(10); } this seems bit strange me. system.threading.thread accesses current thread, not thread started thread pool, , sleep method means "do nothing". current thread waiting thread started taskwrapper instance enter status other none. gets difficult because don't know taskwrapper doing.
it possible it's waiting thread complete execution, there no point having separate thread, because work might done in place of while loop above.
and this:
taskwrapper.join(); the line above anything, depends on implementation of whatever taskwrapper is. based on name guess uses the thread.join method, causes calling thread (this thread) wait until thread it's called on (taskwrapper) has completed. taskwrapper not thread (based on check value of status property above), more it's wrapper around thread.
i've guessed @ honest, doing anything. without seeing code xtthreadpool class , whatever default_pool instance of it's going impossible know sure what's happening.
on first inspection, if code doing i've guessed above there no point having thread work , no point having while loop! whole thing replaced whatever's in method inside call run.
Comments
Post a Comment