From d466e34264b32c7551dd2842adaed69a44408af7 Mon Sep 17 00:00:00 2001 From: WangLin305 Date: Mon, 4 Aug 2025 16:52:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=9F=E5=BC=83=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BB=A3=E7=A0=81=E5=81=A5?= =?UTF-8?q?=E5=A3=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 3 ++- entry/build-profile.json5 | 18 ------------- entry/src/main/ets/common/CommonConstants.ets | 11 +++++++- .../main/ets/common/utils/ThreadMethods.ets | 16 ++++++++++++ entry/src/main/ets/pages/Index.ets | 2 +- entry/src/main/ets/view/DelayedTasks.ets | 20 +++++++++----- entry/src/main/ets/view/DependentTasks.ets | 20 +++++++++----- entry/src/main/ets/view/LongTasks.ets | 26 ++++++++++++++----- entry/src/main/ets/view/PeriodicTasks.ets | 20 +++++++++----- entry/src/main/ets/view/PriorityTasks.ets | 14 ++++++---- entry/src/main/ets/view/SequenceRunner.ets | 20 +++++++++----- entry/src/main/ets/view/TaskGroup.ets | 20 +++++++++----- .../src/main/ets/view/ThreadCommunication.ets | 23 +++++++++++----- 13 files changed, 144 insertions(+), 69 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index eff08eb..b190819 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,11 +1,12 @@ { "app": { - "signingConfigs": [ ], + "signingConfigs": [], "products": [ { "name": "default", "signingConfig": "default", "compatibleSdkVersion": "5.0.0(12)", + "targetSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", "buildOption": { "strictMode": { diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 index 44c0bb4..b789738 100644 --- a/entry/build-profile.json5 +++ b/entry/build-profile.json5 @@ -7,27 +7,9 @@ ] } }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], "targets": [ { "name": "default" - }, - { - "name": "ohosTest", } ] } \ No newline at end of file diff --git a/entry/src/main/ets/common/CommonConstants.ets b/entry/src/main/ets/common/CommonConstants.ets index a4cf67d..519383b 100644 --- a/entry/src/main/ets/common/CommonConstants.ets +++ b/entry/src/main/ets/common/CommonConstants.ets @@ -22,9 +22,18 @@ export class CommonConstants { /** * Page titles. */ - static readonly PAGE_TITLES: Resource[] = [$r('app.string.priorityTask'), $r('app.string.PeriodicTask'), + static readonly PAGE_TITLES: string[] = ['priorityTask', 'PeriodicTask', 'DelayedTask', 'LongTask', 'DependentTask', + 'TaskGroup', 'SequenceRunner', 'ThreadCommunication']; + /** + * Page titles - resource. + */ + static readonly PAGE_TITLES_RESOURCE: Resource[] = [$r('app.string.priorityTask'), $r('app.string.PeriodicTask'), $r('app.string.DelayedTask'), $r('app.string.LongTask'), $r('app.string.DependentTask'), $r('app.string.TaskGroup'), $r('app.string.SequenceRunner'), $r('app.string.ThreadCommunication')]; + /** + * taskpool thread tag. + */ + static readonly TASKPOOL_TAG: string = '[TASKPOOL]'; /** * Page stack name. */ diff --git a/entry/src/main/ets/common/utils/ThreadMethods.ets b/entry/src/main/ets/common/utils/ThreadMethods.ets index 3c83a1b..41af3e9 100644 --- a/entry/src/main/ets/common/utils/ThreadMethods.ets +++ b/entry/src/main/ets/common/utils/ThreadMethods.ets @@ -14,9 +14,11 @@ */ import { process } from '@kit.ArkTS'; +import { hilog } from '@kit.PerformanceAnalysisKit'; import DateTimeUtils from '../utils/DateTimeUtils'; const DATETIME: DateTimeUtils = new DateTimeUtils(); +const TAG:string = '[UTILS]'; export enum ThreadType { main = '[Main] ', @@ -38,4 +40,18 @@ export function timeConsumingTask(time: number) { continue; } return; +} + +export function getResourceString(uiContext: UIContext, resourceName: string): string { + let res = 'Unknown Title'; + let readRes: string|undefined = undefined; + try { + readRes = uiContext.getHostContext()?.resourceManager.getStringByNameSync(resourceName); + } catch (error) { + hilog.error(0x0000, TAG, `getStringByNameSync catch error, code: ${error.code}, message: ${error.message}`); + } + if (readRes) { + res = readRes; + } + return res; } \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 1d4ccc7..b9d2a91 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -34,7 +34,7 @@ struct Index { build() { Navigation(this.pageInfos) { Column({ space: 12 }) { - ForEach(Const.PAGE_TITLES, (item: Resource, index: number) => { + ForEach(Const.PAGE_TITLES_RESOURCE, (item: Resource, index: number) => { Button(item) .attributeModifier(this.customButton) .onClick(() => { diff --git a/entry/src/main/ets/view/DelayedTasks.ets b/entry/src/main/ets/view/DelayedTasks.ets index 0b8b68d..cd0019c 100644 --- a/entry/src/main/ets/view/DelayedTasks.ets +++ b/entry/src/main/ets/view/DelayedTasks.ets @@ -19,14 +19,18 @@ import { ThreadInfos } from '../viewmodel/ThreadInfos'; import { ShowInfoComponent } from '../view/ShowInfoComponent'; import { CommonConstants as Const } from '../common/CommonConstants'; import { CustomButtonModifier, CustomColumnModifier } from '../viewmodel/ComponentModifier'; -import { ThreadType, threadExecuteInfo, timeConsumingTask } from '../common/utils/ThreadMethods'; +import { ThreadType, threadExecuteInfo, timeConsumingTask, getResourceString } from '../common/utils/ThreadMethods'; const TAG: string = '[DelayedTasks]'; @Concurrent function delayedFunc(): void { let exeMsg: string = threadExecuteInfo(ThreadType.taskPool, Const.DELAYED_EXE_INFO); - taskpool.Task.sendData(exeMsg); + try { + taskpool.Task.sendData(exeMsg); + } catch (error) { + hilog.error(0x0000, Const.TASKPOOL_TAG, `sendData catch error, code: ${error.code}, message: ${error.message}`); + } timeConsumingTask(Const.DELAYED_TASK_EXE_TIMES); } @@ -44,9 +48,13 @@ struct DelayedTasks { async refreshInfo(value: string) { let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request(Const.LOCK_NAME); - return lock.lockAsync(() => { - this.executeContents += value; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + try { + lock.lockAsync(() => { + this.executeContents += value; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + } catch (error) { + hilog.error(0x0000, TAG, `lockAsync catch error, code: ${error.code}, message: ${error.message}`); + } } build() { @@ -101,7 +109,7 @@ struct DelayedTasks { } .width('100%') .height('100%') - .title(this.getUIContext().getHostContext()?.resourceManager.getStringSync(Const.PAGE_TITLES[2])) + .title(getResourceString(this.getUIContext(), Const.PAGE_TITLES[2])) .backgroundColor(0XF1F3F5) .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) .onAppear(() => { diff --git a/entry/src/main/ets/view/DependentTasks.ets b/entry/src/main/ets/view/DependentTasks.ets index d3fd3fb..70bc2ce 100644 --- a/entry/src/main/ets/view/DependentTasks.ets +++ b/entry/src/main/ets/view/DependentTasks.ets @@ -19,14 +19,18 @@ import { ThreadInfos } from '../viewmodel/ThreadInfos'; import { ShowInfoComponent } from '../view/ShowInfoComponent'; import { CommonConstants as Const } from '../common/CommonConstants'; import { CustomButtonModifier, CustomColumnModifier } from '../viewmodel/ComponentModifier'; -import { ThreadType, threadExecuteInfo, timeConsumingTask } from '../common/utils/ThreadMethods'; +import { ThreadType, threadExecuteInfo, timeConsumingTask, getResourceString } from '../common/utils/ThreadMethods'; const TAG: string = '[DependentTasks]'; @Concurrent function dependentFunc(num: number): void { let exeMsg: string = threadExecuteInfo(ThreadType.taskPool, Const.DEPENDENT_EXE_INFO + num.toString()); - taskpool.Task.sendData(exeMsg); + try { + taskpool.Task.sendData(exeMsg); + } catch (error) { + hilog.error(0x0000, Const.TASKPOOL_TAG, `sendData catch error, code: ${error.code}, message: ${error.message}`); + } timeConsumingTask(Const.DEPENDENT_TASK_EXE_TIMES); } @@ -44,9 +48,13 @@ struct DependentTasks { async refreshInfo(value: string) { let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request(Const.LOCK_NAME); - return lock.lockAsync(() => { - this.executeContents += value; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + try { + lock.lockAsync(() => { + this.executeContents += value; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + } catch (error) { + hilog.error(0x0000, TAG, `lockAsync catch error, code: ${error.code}, message: ${error.message}`); + } } build() { @@ -110,7 +118,7 @@ struct DependentTasks { } .width('100%') .height('100%') - .title(this.getUIContext().getHostContext()?.resourceManager.getStringSync(Const.PAGE_TITLES[4])) + .title(getResourceString(this.getUIContext(), Const.PAGE_TITLES[4])) .backgroundColor(0XF1F3F5) .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) .onAppear(() => { diff --git a/entry/src/main/ets/view/LongTasks.ets b/entry/src/main/ets/view/LongTasks.ets index 93833ed..70e696a 100644 --- a/entry/src/main/ets/view/LongTasks.ets +++ b/entry/src/main/ets/view/LongTasks.ets @@ -19,17 +19,25 @@ import { ThreadInfos } from '../viewmodel/ThreadInfos'; import { ShowInfoComponent } from '../view/ShowInfoComponent'; import { CommonConstants as Const } from '../common/CommonConstants'; import { CustomButtonModifier, CustomColumnModifier } from '../viewmodel/ComponentModifier'; -import { ThreadType, threadExecuteInfo, timeConsumingTask } from '../common/utils/ThreadMethods'; +import { ThreadType, threadExecuteInfo, timeConsumingTask, getResourceString } from '../common/utils/ThreadMethods'; const TAG: string = '[LongTasks]'; @Concurrent function longFunc(): void { let exeMsg: string = threadExecuteInfo(ThreadType.taskPool, Const.LONG_EXE_INFO); - taskpool.Task.sendData(exeMsg); + try { + taskpool.Task.sendData(exeMsg); + } catch (error) { + hilog.error(0x0000, Const.TASKPOOL_TAG, `sendData catch error, code: ${error.code}, message: ${error.message}`); + } timeConsumingTask(Const.LONG_TASK_EXE_TIMES); exeMsg = threadExecuteInfo(ThreadType.taskPool, Const.LONG_END_INFO); - taskpool.Task.sendData(exeMsg); + try { + taskpool.Task.sendData(exeMsg); + } catch (error) { + hilog.error(0x0000, Const.TASKPOOL_TAG, `sendData catch error, code: ${error.code}, message: ${error.message}`); + } } @Component @@ -46,9 +54,13 @@ struct LongTasks { async refreshInfo(value: string) { let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request(Const.LOCK_NAME); - return lock.lockAsync(() => { - this.executeContents += value; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + try { + lock.lockAsync(() => { + this.executeContents += value; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + } catch (error) { + hilog.error(0x0000, TAG, `lockAsync catch error, code: ${error.code}, message: ${error.message}`); + } } build() { @@ -102,7 +114,7 @@ struct LongTasks { } .width('100%') .height('100%') - .title(this.getUIContext().getHostContext()?.resourceManager.getStringSync(Const.PAGE_TITLES[3])) + .title(getResourceString(this.getUIContext(), Const.PAGE_TITLES[3])) .backgroundColor(0XF1F3F5) .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) .onAppear(() => { diff --git a/entry/src/main/ets/view/PeriodicTasks.ets b/entry/src/main/ets/view/PeriodicTasks.ets index b0a2038..acb421b 100644 --- a/entry/src/main/ets/view/PeriodicTasks.ets +++ b/entry/src/main/ets/view/PeriodicTasks.ets @@ -19,14 +19,18 @@ import { ThreadInfos } from '../viewmodel/ThreadInfos'; import { ShowInfoComponent } from '../view/ShowInfoComponent'; import { CommonConstants as Const } from '../common/CommonConstants'; import { CustomButtonModifier, CustomColumnModifier } from '../viewmodel/ComponentModifier'; -import { ThreadType, threadExecuteInfo, timeConsumingTask } from '../common/utils/ThreadMethods'; +import { ThreadType, threadExecuteInfo, timeConsumingTask, getResourceString } from '../common/utils/ThreadMethods'; const TAG: string = '[PeriodicTasks]'; @Concurrent function periodicFunc(): void { let exeMsg: string = threadExecuteInfo(ThreadType.taskPool, Const.PERIODIC_EXE_INFO); - taskpool.Task.sendData(exeMsg); + try { + taskpool.Task.sendData(exeMsg); + } catch (error) { + hilog.error(0x0000, Const.TASKPOOL_TAG, `sendData catch error, code: ${error.code}, message: ${error.message}`); + } timeConsumingTask(Const.PERIODIC_TASK_EXE_TIMES); } @@ -44,9 +48,13 @@ struct PeriodicTasks { async refreshInfo(value: string) { let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request(Const.LOCK_NAME); - return lock.lockAsync(() => { - this.executeContents += value; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + try { + lock.lockAsync(() => { + this.executeContents += value; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + } catch (error) { + hilog.error(0x0000, TAG, `lockAsync catch error, code: ${error.code}, message: ${error.message}`); + } } build() { @@ -98,7 +106,7 @@ struct PeriodicTasks { } .width('100%') .height('100%') - .title(this.getUIContext().getHostContext()?.resourceManager.getStringSync(Const.PAGE_TITLES[1])) + .title(getResourceString(this.getUIContext(), Const.PAGE_TITLES[1])) .backgroundColor(0XF1F3F5) .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) .onAppear(() => { diff --git a/entry/src/main/ets/view/PriorityTasks.ets b/entry/src/main/ets/view/PriorityTasks.ets index 79fae93..a3aff22 100644 --- a/entry/src/main/ets/view/PriorityTasks.ets +++ b/entry/src/main/ets/view/PriorityTasks.ets @@ -19,7 +19,7 @@ import { ThreadInfos } from '../viewmodel/ThreadInfos'; import { ShowInfoComponent } from '../view/ShowInfoComponent'; import { CommonConstants as Const } from '../common/CommonConstants'; import { CustomButtonModifier, CustomColumnModifier } from '../viewmodel/ComponentModifier'; -import { ThreadType, threadExecuteInfo, timeConsumingTask } from '../common/utils/ThreadMethods'; +import { ThreadType, threadExecuteInfo, timeConsumingTask, getResourceString } from '../common/utils/ThreadMethods'; const TAG: string = '[PriorityTasks]'; @@ -44,9 +44,13 @@ struct PriorityTasks { async refreshInfo(value: string) { let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request(Const.LOCK_NAME); - return lock.lockAsync(() => { - this.executeContents += value; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + try { + lock.lockAsync(() => { + this.executeContents += value; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + } catch (error) { + hilog.error(0x0000, TAG, `lockAsync catch error, code: ${error.code}, message: ${error.message}`); + } } build() { @@ -113,7 +117,7 @@ struct PriorityTasks { } .width('100%') .height('100%') - .title(this.getUIContext().getHostContext()?.resourceManager.getStringSync(Const.PAGE_TITLES[0])) + .title(getResourceString(this.getUIContext(), Const.PAGE_TITLES[0])) .backgroundColor(0XF1F3F5) .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) .onAppear(() => { diff --git a/entry/src/main/ets/view/SequenceRunner.ets b/entry/src/main/ets/view/SequenceRunner.ets index 43fbc23..84484f9 100644 --- a/entry/src/main/ets/view/SequenceRunner.ets +++ b/entry/src/main/ets/view/SequenceRunner.ets @@ -19,14 +19,18 @@ import { ThreadInfos } from '../viewmodel/ThreadInfos'; import { ShowInfoComponent } from '../view/ShowInfoComponent'; import { CommonConstants as Const } from '../common/CommonConstants'; import { CustomButtonModifier, CustomColumnModifier } from '../viewmodel/ComponentModifier'; -import { ThreadType, threadExecuteInfo, timeConsumingTask } from '../common/utils/ThreadMethods'; +import { ThreadType, threadExecuteInfo, timeConsumingTask, getResourceString } from '../common/utils/ThreadMethods'; const TAG: string = '[SequenceRunner]'; @Concurrent function sequenceRunnerFunc(num: number): void { let exeMsg: string = threadExecuteInfo(ThreadType.taskPool, Const.RUNNER_EXE_INFO + num.toString()); - taskpool.Task.sendData(exeMsg); + try { + taskpool.Task.sendData(exeMsg); + } catch (error) { + hilog.error(0x0000, Const.TASKPOOL_TAG, `sendData catch error, code: ${error.code}, message: ${error.message}`); + } timeConsumingTask(Const.RUNNER_EXE_TIMES); } @@ -45,9 +49,13 @@ struct SequenceRunner { async refreshInfo(value: string) { let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request(Const.LOCK_NAME); - return lock.lockAsync(() => { - this.executeContents += value; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + try { + lock.lockAsync(() => { + this.executeContents += value; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + } catch (error) { + hilog.error(0x0000, TAG, `lockAsync catch error, code: ${error.code}, message: ${error.message}`); + } } build() { @@ -110,7 +118,7 @@ struct SequenceRunner { } .width('100%') .height('100%') - .title(this.getUIContext().getHostContext()?.resourceManager.getStringSync(Const.PAGE_TITLES[6])) + .title(getResourceString(this.getUIContext(), Const.PAGE_TITLES[6])) .backgroundColor(0XF1F3F5) .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) .onAppear(() => { diff --git a/entry/src/main/ets/view/TaskGroup.ets b/entry/src/main/ets/view/TaskGroup.ets index 3c92945..38ca043 100644 --- a/entry/src/main/ets/view/TaskGroup.ets +++ b/entry/src/main/ets/view/TaskGroup.ets @@ -19,14 +19,18 @@ import { ThreadInfos } from '../viewmodel/ThreadInfos'; import { ShowInfoComponent } from '../view/ShowInfoComponent'; import { CommonConstants as Const } from '../common/CommonConstants'; import { CustomButtonModifier, CustomColumnModifier } from '../viewmodel/ComponentModifier'; -import { ThreadType, threadExecuteInfo, timeConsumingTask } from '../common/utils/ThreadMethods'; +import { ThreadType, threadExecuteInfo, timeConsumingTask, getResourceString } from '../common/utils/ThreadMethods'; const TAG: string = '[TaskGroup]'; @Concurrent function taskGroupFunc(num: number): void { let exeMsg: string = threadExecuteInfo(ThreadType.taskPool, Const.GROUP_EXE_INFO + num.toString()); - taskpool.Task.sendData(exeMsg); + try { + taskpool.Task.sendData(exeMsg); + } catch (error) { + hilog.error(0x0000, Const.TASKPOOL_TAG, `sendData catch error, code: ${error.code}, message: ${error.message}`); + } timeConsumingTask(Const.GROUP_EXE_TIMES); } @@ -45,9 +49,13 @@ struct TaskGroup { async refreshInfo(value: string) { let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request(Const.LOCK_NAME); - return lock.lockAsync(() => { - this.executeContents += value; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + try { + lock.lockAsync(() => { + this.executeContents += value; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + } catch (error) { + hilog.error(0x0000, TAG, `lockAsync catch error, code: ${error.code}, message: ${error.message}`); + } } build() { @@ -106,7 +114,7 @@ struct TaskGroup { } .width('100%') .height('100%') - .title(this.getUIContext().getHostContext()?.resourceManager.getStringSync(Const.PAGE_TITLES[5])) + .title(getResourceString(this.getUIContext(), Const.PAGE_TITLES[5])) .backgroundColor(0XF1F3F5) .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) .onAppear(() => { diff --git a/entry/src/main/ets/view/ThreadCommunication.ets b/entry/src/main/ets/view/ThreadCommunication.ets index 958cd12..8eb41d1 100644 --- a/entry/src/main/ets/view/ThreadCommunication.ets +++ b/entry/src/main/ets/view/ThreadCommunication.ets @@ -15,16 +15,23 @@ import { emitter } from '@kit.BasicServicesKit'; import { taskpool, ArkTSUtils, worker, MessageEvents } from '@kit.ArkTS'; +import { hilog } from '@kit.PerformanceAnalysisKit'; import { ThreadInfos } from '../viewmodel/ThreadInfos'; import { ShowInfoComponent } from '../view/ShowInfoComponent'; import { CommonConstants as Const } from '../common/CommonConstants'; import { CustomButtonModifier, CustomColumnModifier } from '../viewmodel/ComponentModifier'; -import { ThreadType, threadExecuteInfo, timeConsumingTask } from '../common/utils/ThreadMethods'; +import { ThreadType, threadExecuteInfo, timeConsumingTask, getResourceString } from '../common/utils/ThreadMethods'; + +const TAG: string = '[ThreadCommunication]'; @Concurrent function taskPoolFunc(): void { let sendMsg: string = threadExecuteInfo(ThreadType.taskPool, Const.SEND_MESSAGES); - taskpool.Task.sendData(sendMsg); + try { + taskpool.Task.sendData(sendMsg); + } catch (error) { + hilog.error(0x0000, Const.TASKPOOL_TAG, `sendData catch error, code: ${error.code}, message: ${error.message}`); + } timeConsumingTask(Const.Communication_EXE_TIMES); } @@ -56,9 +63,13 @@ struct ThreadCommunication { async refreshInfo(value: string) { let lock: ArkTSUtils.locks.AsyncLock = ArkTSUtils.locks.AsyncLock.request(Const.LOCK_NAME); - return lock.lockAsync(() => { - this.executeContents += value; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + try { + lock.lockAsync(() => { + this.executeContents += value; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE); + } catch (error) { + hilog.error(0x0000, TAG, `lockAsync catch error, code: ${error.code}, message: ${error.message}`); + } } build() { @@ -105,7 +116,7 @@ struct ThreadCommunication { } .width('100%') .height('100%') - .title(this.getUIContext().getHostContext()?.resourceManager.getStringSync(Const.PAGE_TITLES[7])) + .title(getResourceString(this.getUIContext(), Const.PAGE_TITLES[7])) .backgroundColor(0XF1F3F5) .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) .onAppear(() => { -- Gitee