Repository navigation
Conversation
- skipSearch 一旦因为 WMI 连续失败 3 次被置 true,之后永远不再复位, 之后所有刷新都只剩 SerialPort.GetPortNames() 的兜底项,表现为列表变空/ 没有设备名;现在每次刷新开头复位它 - ManagementObjectSearcher/ManagementObject 用完没释放,长时间挂着软件 反复刷新会漏句柄,改为 using 释放 - 微软库 \0 截断的兜底判断是 IndexOf > 0,字符串以 \0 开头时不生效,改为 >= 0 Fixes chenxuuu#210
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #210
顺着「开机时间长 + 软件一直开着,串口列表就空掉」这条线看,
refreshPortList()里有三个问题,第一个能直接解释「列表没了」:skipSearch一旦置 true 就再也不会复位。WMI 查询连续失败 3 次(searchCount >= 3)会把它设为 true,之后每次刷新的while (!skipSearch)直接不进循环,只剩SerialPort.GetPortNames()那段兜底;兜底项本来就没有设备名,看起来就是「串口列表不显示」。现在每次刷新开头复位它。ManagementObjectSearcher和每次searcher.Get()出来的ManagementObject都没 Dispose,挂一天反复刷新会一直涨句柄,久了枚举变慢/失败,正好是「时间越长越容易出现」的形态。改成using。\0截断的兜底判断写成了IndexOf("\0") > 0,字符串以\0开头时不生效(应该是>= 0),顺手改掉。说明:本机是 Linux,这个 WPF 老式 csproj 编不了,没法实跑验证;如果有可复现的环境,麻烦看一下失败 3 次后点刷新是不是能重新拿到带设备名的列表。