{"record":{"id":"dc8adedc9af6fb65","repo":"babalae/better-genshin-impact","slug":"bvflow-dc8ade","errorCode":null,"errorMessage":"BvFlow 已经开始执行，不能再添加步骤","messagePattern":"BvFlow 已经开始执行，不能再添加步骤","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/BgiVision/BvFlow.cs","lineNumber":277,"sourceCode":"    }\n\n    internal BvFlow AddActionStep(BvFlowActionSnapshot snapshot)\n    {\n        return AddStep(snapshot.Description, context => ExecuteActionStep(snapshot, context));\n    }\n\n    internal BvFlow AddOnceActionStep(string description, Func<BvFlowExecutionContext, Task> action)\n    {\n        return AddStep(description, action);\n    }\n\n    internal BvFlowAction CreateAction(string description, Func<BvFlowExecutionContext, Task> action)\n    {\n        lock (_syncRoot)\n        {\n            if (_hasStarted)\n            {\n                throw new InvalidOperationException(\"BvFlow 已经开始执行，不能再添加步骤\");\n            }\n        }\n\n        return new BvFlowAction(this, description, action);\n    }\n\n    internal BvLocator CreateTextLocator(string text, Rect rect)\n    {\n        return _page.Locator(new RecognitionObject\n        {\n            RecognitionType = RecognitionTypes.Ocr,\n            RegionOfInterest = rect,\n            Text = text\n        });\n    }\n\n    internal BvLocator CreateAnyTextLocator(object texts, Rect rect)\n    {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/BgiVision/BvFlow.cs#L259-L295","documentation":"Thrown from SetSmartSizing when the already-connected RDP ActiveX control's AdvancedSettings7 property returns null. Unlike the connect-time variant (errorIndex 2), this fires post-connection when toggling display scaling at runtime. It indicates the control's COM state degraded after the initial connection or the control was disposed/recreated between connect and this call.","triggerScenarios":"SetSmartSizing is called after IsHandleCreated is true, reads AdvancedSettings7 from GetRequiredOcx(). Returns null if the AxHost handle was recreated (e.g. parent visibility change) causing GetOcx() to return a stale/null reference, or if the control is mid-disposal.","commonSituations":"User toggles smart-sizing while the child session window is being resized/restored, the WindowsFormsHost reparents the AxHost causing handle recreation, or the RDP session disconnected and the control is in a transitional state.","solutions":["Guard SetSmartSizing with a check that ConnectedState == 1 and the control is not disposing before accessing AdvancedSettings7.","Cache the setting in _smartSizingEnabled (already done) and re-apply it on next ConnectToChildSession rather than throwing post-disconnect.","Wrap the property access in try-catch and log a warning instead of throwing when the control is in a transitional state."],"exampleFix":"// before\ninternal void SetSmartSizing(bool enabled)\n{\n    _smartSizingEnabled = enabled;\n    if (!IsHandleCreated) return;\n    var advancedSettings = GetComProperty(GetRequiredOcx(), \"AdvancedSettings7\")\n        ?? throw new COMException(\"RDP ActiveX 未返回 AdvancedSettings7。\");\n    RunComStep(\"设置显示缩放\", () => SetComProperty(advancedSettings, \"SmartSizing\", enabled));\n}\n\n// after — silently cache if control is in transition\ninternal void SetSmartSizing(bool enabled)\n{\n    _smartSizingEnabled = enabled;\n    if (!IsHandleCreated || IsDisposed || ConnectedState != 1) return;\n    var advancedSettings = GetComProperty(GetRequiredOcx(), \"AdvancedSettings7\");\n    if (advancedSettings is null) return; // will be re-applied on next connect\n    RunComStep(\"设置显示缩放\", () => SetComProperty(advancedSettings, \"SmartSizing\", enabled));\n}","handlingStrategy":"validation","validationCode":"// Guard SetSmartSizing against transitional control states\nif (!IsHandleCreated || IsDisposed || Disposing || ConnectedState != 1)\n    return; // _smartSizingEnabled is cached; will apply on next connect","typeGuard":"bool IsControlReadyForPropertySet() =>\n    IsHandleCreated && !IsDisposed && !Disposing && ConnectedState == 1;","tryCatchPattern":"try { SetComProperty(advancedSettings, \"SmartSizing\", enabled); }\ncatch (COMException) { /* non-fatal: cached value applies on reconnect */ }","preventionTips":["Always cache runtime toggle values so they survive control recreation.","Suppress property-set calls when the control is disposing or disconnected.","Re-apply all cached settings in ConnectToChildSession to recover from transient failures."],"tags":["rdp","com","activex","child-session","runtime-toggle"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}