中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
宿主线程如何向worker子线程发送消息?
微信扫码分享
//宿主线程代码: import worker from '@ohos.worker'; workerInstance: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/Myworker.ts'); Button("发消息给子线程").onClick(() => { this.workerInstance.postMessage({ name: "Tom" }) }) //Myworker子线程中接收消息 workerPort.onmessage = (e: MessageEvents) => { console.log("========================接收到消息"+JSON.stringify(e)) }