Skip to content

Conversation

@Duck15
Copy link

@Duck15 Duck15 commented Jul 25, 2025

fix(chatvpet): 解决工作控制功能的线程冲突问题

问题描述
当通过插件API调用ToolStopWorkToolSleep时,因非UI线程直接操作WPF控件,抛出InvalidOperationException

修复方案

  1. 使用Dispatcher.Invoke封装工作停止和睡眠功能的UI操作

影响模块

  • VPet.Plugin.ChatVPet.CVPPlugin

@LorisYounger LorisYounger requested a review from Copilot July 25, 2025 12:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes thread safety issues when calling work control functions (ToolStopWork and ToolSleep) through the plugin API, which previously caused InvalidOperationException when non-UI threads attempted to directly manipulate WPF controls.

  • Wraps UI operations in Dispatcher.Invoke for thread-safe access to WPF controls
  • Adds project configuration changes for Windows targeting and self-contained deployment
  • Improves error handling by replacing label displays with message boxes

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
VPet.Plugin.ChatVPet.csproj Adds Windows targeting and self-contained deployment configuration
CVP_Tool.cs Wraps work control operations in Dispatcher.Invoke for thread safety
CVPTTalkAPI.cs Replaces label error displays with message boxes and adds thread safety
Comments suppressed due to low confidence (3)

VPet.Plugin.ChatVPet/VPet.Plugin.ChatVPet.csproj:9

  • The property name should use PascalCase. Change 'selfContained' to 'SelfContained' to follow MSBuild property naming conventions.
   <selfContained>true</selfContained>

VPet.Plugin.ChatVPet/CVP_Tool.cs:89

  • The removed line was calling WorkTimer.Stop() outside of Dispatcher.Invoke, but this call is now missing from the ToolSleep method. The work timer should be stopped before checking the state or within the Dispatcher.Invoke block.
        {

VPet.Plugin.ChatVPet/CVPTTalkAPI.cs:161

  • [nitpick] The method name 'DisplayThinkToSayRndAutoNoForce' is unclear and overly long. Consider using a more descriptive name that clearly indicates its purpose.
                DisplayThinkToSayRndAutoNoForce("API调用失败".Translate() + $",{str}\n{e}"); //, GraphCore.Helper.SayType.Serious);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant