multithreading - Delphi Access to Thread Variables -
i have thread wmi query me , need access variables in thread after has executed query.
the thread created follows ...
procedure tformmain.runthread; var wmiq: tthreadwmiquery; begin wmiq := tthreadwmiquery.create(true); ... wmiq.onterminate := wmiqthreadonterminate; wmiq.resume; end;
and in onterminate event values need ...
procedure tformmain.wmiqthreadonterminate(sender: tobject); begin opcd := tthreadwmiquery(sender).p4copcd; role := tthreadwmiquery(sender).p4crole; usnm := tthreadwmiquery(sender).p4cusnm; end;
i've been told may not best way access thread variables. there other, better, ways can data thread without complexity?
regards, pieter
who told that? did give reasons?
onterminate there query thread instance after has finished executing , before destroyed. in fact, when set tthread's freeonterminate true, have no other place access thread's variables.
other mechanisms:
global variable set thread, queried elsewhere : yuck , still need use onterminate know when thread finished. better keep variables local thread itself.
using postthreadmessage thread: post to? mean letting thread know whom post these message , kind of observer mechanism.
the first i'd not recommend. second imho overkill if need query couple of values upon thread termination.
Comments
Post a Comment