Send a message in a task. It can be a function or an object method.
TOmniTaskMessageEvent = procedure(const task: IOmniTaskControl; const msg: TOmniMessage) of object; TOmniOnTerminatedFunction = reference to procedure(const task: IOmniTaskControl);
Program Main; {$ apptype console} {$ R *. res} uses system. sysutils, system. classes, otlparallel, otltask, otltaskcontrol, otlcomm, otlcommon, idhttp, Web. httpapp, winapi. windows, winapi. messages; const wm_result = wm_user; Procedure httpget (host, URL: string); var http: tidhttp; begin http: = tidhttp. create; // HTTP. request. HOST: = host; http. request. method: = 'get'; http. request. useragent: = 'mozilla/5.0 (Windows NT 6.1; wow64) applewebkit/537.36 (khtml, like gecko) Chrome/36.0.1985.125 Safari/80'; http. request. acceptlanguage: = 'zh-CN, ZH; q = 66661'; http. get (host + URL ); writeln ('============================== Response Header ==================== =========== '); writeln ('server: '+ HTTP. response. server); writeln ('status code: '+ HTTP. response. responsecode. tostring); writeln ('charset: '+ HTTP. response. charset); writeln ('contentlength: '+ HTTP. response. contentlength. tostring (); writeln ('contenttype: '+ HTTP. response. contenttype); http. free; end; Procedure logresult (const task: iomnitaskcontrol; const MSG: tomnimessage); begin writeln (format ('asynchronous get: % s', [MSG. msgdata. casttostringdef ('')]); end; begin {send messages asynchronously} parallel. async (Procedure (const task: iomnitask) var MSG: string; begin writeln ('thread id' + getcurrentthreadid. tostring (); MSG: = 'task1 Start'; task. comm. send (wm_result, MSG); httpget ('HTTP: // zh.wikipedia.org/', string (httpencode ('wiki/document'); task. comm. send (wm_result, 'task1 completed'); End, parallel. taskconfig. onmessage (wm_result, logresult); readln; end.
1. The message is not received... it's strange.