Omnithreadlibary Learning (3)-iomnitask asynchronously executes sendmessage

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.