【语言-c#】托管调试助手“DisconnectedContext”在“xxx.exe”中检测到问题。 RPC_E_CANTCALLOUT_ININPUTSYNCCALL

问题描述

托管调试助手“DisconnectedContext”在“[ProjectDirectory]\[ProjectName].exe”中检测到问题。

其他信息: 针对此 RuntimeCallableWrapper 向 COM 上下文 0x8306e8 的转换失败,错误如下: 因为应用程序正在发送一个输入同步呼叫,所以无法执行传出的呼叫。 (异常来自 HRESULT:0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL))。原因通常是创建此 RuntimeCallableWrapper 的 COM 上下文 0x8306e8 已断开连接,或者该上下文正忙于执行其他操作,无法处理该上下文转换。将不会有代理服务于该 COM 组件上的请求,调用将直接转向该 COM 组件。这可能会导致损坏或数据丢失。要避免此问题,请确保在应用程序全部完成 RuntimeCallableWrapper (表示其内部的 COM 组件)之前,所有 COM 上下文/单元/线程都保持活动状态并可用于上下文转换。

 

问题代码

 问题位置 :var hardinfos = searcher.Get();

namespace SMQH
{
    public class hosComputerSystemHardware
    {
        public bool Main()
        {
            try
            {
                string[] comstr = GetSerialPortList();
                if (comstr == null)
                {
                    System.Diagnostics.Debug.WriteLine("not find serial port!");
                    return false;
                }
                for (int i = 0; i < comstr.Length; i++)
                {
                    System.Diagnostics.Debug.WriteLine(comstr[i]);

                }
            }
            catch (System.IO.IOException exp)
            {
                System.Diagnostics.Debug.WriteLine(exp.Message);
                return false;
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine(exp.Message);
                return false;
            }
            return false;
        }

        /// <summary>
        /// 获取硬件设备信息
        /// </summary>
        /// <param name="eType">设备类型</param>
        /// <param name="Keyvalue">硬件名称</param>
        /// <returns></returns>
        private static string[] MulGetHardwareInfo(ComputerSystemHardwareClasses eType, Win32_PnPEntitySection Keyvalue)
        {
            List<string> strs = new List<string>();
            try
            {
                using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + eType))
                {
                    //  ManagementObjectCollection hardinfos = searcher.Get();
                    var hardinfos = searcher.Get();
                    foreach (var hardinfo in hardinfos)
                    {
                        if (hardinfo.Properties[Keyvalue.ToString()].Value != null)
                        {
                            if (hardinfo.Properties[Keyvalue.ToString()].Value.ToString().Contains("COM"))
                            {
                                strs.Add(hardinfo.Properties[Keyvalue.ToString()].Value.ToString());
                            }
                        }
                    }
                    searcher.Dispose();
                }
                return strs.ToArray();
            }
            catch (Exception exp)
            {
                System.Windows.Forms.MessageBox.Show(exp.Message, "异常");
                return null;
            }
        }
        /// <summary>
        /// 获取串口列表
        /// </summary>
        /// <returns></returns>
        private static string[] GetSerialPortList()
        {
            return MulGetHardwareInfo(ComputerSystemHardwareClasses.Win32_PnPEntity, Win32_PnPEntitySection.Name);
        }
    }
}

解决方案

创建线程来调用接口

namespace SMQH
{
    public class hosComputerSystemHardware
    {
        /// <summary>
        /// 读值线程
        /// </summary>
        private System.Threading.Thread threadReadValue = null;
        /// <summary>
        /// 局部变量 用来存储返回结果
        /// </summary>
        private string[] PortNameArray = null;
        /// <summary>
        /// 是否结束
        /// </summary>
        public bool ReadOver = true;
        public bool Main()
        {
            try
            {
                string[] comstr = GetSerialPortArray();
                if (comstr == null)
                {
                    System.Diagnostics.Debug.WriteLine("not find serial port!");
                    return false;
                }
                for (int i = 0; i < comstr.Length; i++)
                {
                    System.Diagnostics.Debug.WriteLine(comstr[i]);

                }
            }
            catch (System.IO.IOException exp)
            {
                System.Diagnostics.Debug.WriteLine(exp.Message);
                return false;
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine(exp.Message);
                return false;
            }
            return false;
        }

        /// <summary>
        /// 获取串口列表线程
        /// </summary>
        private void OnGetSerialPortList()
        {
            try
            {
                PortNameArray = GetSerialPortList();
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine(exp.Message);
            }
            ReadOver = true;
        }

        /// <summary>
        /// 通过线程获取串口列表
        /// </summary>
        public string[] GetSerialPortArray()
        {
            PortNameArray = null;
            try
            {
                threadReadValue = new System.Threading.Thread(OnGetSerialPortList);
                threadReadValue.IsBackground = true;
                ReadOver = false;
                threadReadValue.Start();

                while (ReadOver == false)
                {
                    System.Threading.Thread.Sleep(200);
                }
                threadReadValue = null;
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine(exp.Message);
            }
            return PortNameArray;
        }

        /// <summary>
        /// 获取硬件设备信息
        /// </summary>
        /// <param name="eType">设备类型</param>
        /// <param name="Keyvalue">硬件名称</param>
        /// <returns></returns>
        private static string[] MulGetHardwareInfo(ComputerSystemHardwareClasses eType, Win32_PnPEntitySection Keyvalue)
        {
            List<string> strs = new List<string>();
            try
            {
                using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + eType))
                {
                    //  ManagementObjectCollection hardinfos = searcher.Get();
                    var hardinfos = searcher.Get();
                    foreach (var hardinfo in hardinfos)
                    {
                        if (hardinfo.Properties[Keyvalue.ToString()].Value != null)
                        {
                            if (hardinfo.Properties[Keyvalue.ToString()].Value.ToString().Contains("COM"))
                            {
                                strs.Add(hardinfo.Properties[Keyvalue.ToString()].Value.ToString());
                            }
                        }
                    }
                    searcher.Dispose();
                }
                return strs.ToArray();
            }
            catch (Exception exp)
            {
                System.Windows.Forms.MessageBox.Show(exp.Message, "异常");
                return null;
            }
        }
        /// <summary>
        /// 获取串口列表
        /// </summary>
        /// <returns></returns>
        private static string[] GetSerialPortList()
        {
            return MulGetHardwareInfo(ComputerSystemHardwareClasses.Win32_PnPEntity, Win32_PnPEntitySection.Name);
        }
    }
}

 

 

辅助代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Data;
using System.ServiceProcess;
using NHChemi.BIOOIInfo;
using System.Text.RegularExpressions;
using System.Management;
using System.IO;

namespace SMQH
{
    /// <summary>
    /// 电脑系统硬件类
    /// </summary>
    public enum ComputerSystemHardwareClasses
    {
        Win32_1394Controller,
        Win32_1394ControllerDevice,
        Win32_Fan,
        Win32_HeatPipe,
        Win32_Refrigeration,
        Win32_TemperatureProbe,
        Win32_AssociatedProcessorMemory,
        Win32_AutochkSetting,
        Win32_BaseBoard,
        Win32_Battery,
        Win32_BIOS,
        Win32_Bus,
        Win32_CacheMemory,
        Win32_CDROMDrive,
        Win32_CIMLogicalDeviceCIMDataFile,
        Win32_ComputerSystemProcessor,
        Win32_CurrentProbe,
        Win32_DesktopMonitor,
        Win32_DeviceBus,
        Win32_DeviceChangeEvent,
        Win32_DeviceMemoryAddress,
        Win32_DeviceSettings,
        Win32_DiskDrive,
        Win32_DiskDriveToDiskPartition,
        Win32_DiskPartition,
        Win32_DisplayControllerConfiguration,
        Win32_DMAChannel,
        Win32_DriverForDevice,
        Win32_FloppyController,
        Win32_FloppyDrive,
        Win32_IDEController,
        Win32_IDEControllerDevice,
        Win32_InfraredDevice,
        Win32_IRQResource,
        Win32_Keyboard,
        Win32_LogicalDisk,
        Win32_LogicalDiskRootDirectory,
        Win32_LogicalDiskToPartition,
        Win32_LogicalProgramGroup,
        Win32_LogicalProgramGroupDirectory,
        Win32_LogicalProgramGroupItem,
        Win32_LogicalProgramGroupItemDataFile,
        Win32_MappedLogicalDisk,
        Win32_MemoryArray,
        Win32_MemoryArrayLocation,
        Win32_MemoryDevice,
        Win32_MemoryDeviceArray,
        Win32_MemoryDeviceLocation,
        Win32_MotherboardDevice,
        Win32_NetworkAdapter,
        Win32_NetworkAdapterConfiguration,
        Win32_NetworkAdapterSetting,
        Win32_NetworkClient,
        Win32_NetworkConnection,
        Win32_NetworkLoginProfile,
        Win32_NetworkProtocol,
        Win32_OnBoardDevice,
        Win32_ParallelPort,
        Win32_PCMCIAController,
        Win32_PhysicalMemory,
        Win32_PhysicalMemoryArray,
        Win32_PhysicalMemoryLocation,
        Win32_PnPAllocatedResource,
        Win32_PnPDevice,
        Win32_PnPDeviceProperty,
        Win32_PnPDevicePropertyUint8,
        Win32_PnPDevicePropertyUint16,
        Win32_PnPDevicePropertyUint32,
        Win32_PnPDevicePropertyUint64,
        Win32_PnPDevicePropertySint8,
        Win32_PnPDevicePropertySint16,
        Win32_PnPDevicePropertySint32,
        Win32_PnPDevicePropertySint64,
        Win32_PnPDevicePropertyString,
        Win32_PnPDevicePropertyBoolean,
        Win32_PnPDevicePropertyReal32,
        Win32_PnPDevicePropertyReal64,
        Win32_PnPDevicePropertyDateTime,
        Win32_PnPDevicePropertySecurityDescriptor,
        Win32_PnPDevicePropertyBinary,
        Win32_PnPDevicePropertyUint16Array,
        Win32_PnPDevicePropertyUint32Array,
        Win32_PnPDevicePropertyUint64Array,
        Win32_PnPDevicePropertySint8Array,
        Win32_PnPDevicePropertySint16Array,
        Win32_PnPDevicePropertySint32Array,
        Win32_PnPDevicePropertySint64Array,
        Win32_PnPDevicePropertyStringArray,
        Win32_PnPDevicePropertyBooleanArray,
        Win32_PnPDevicePropertyReal32Array,
        Win32_PnPDevicePropertyReal64Array,
        Win32_PnPDevicePropertyDateTimeArray,
        Win32_PnPDevicePropertySecurityDescriptorArray,
        Win32_PnPEntity,
        Win32_PointingDevice,
        Win32_PortableBattery,
        Win32_PortConnector,
        Win32_PortResource,
        Win32_POTSModem,
        Win32_POTSModemToSerialPort,
        Win32_Printer,
        Win32_PrinterConfiguration,
        Win32_PrinterController,
        Win32_PrinterDriver,
        Win32_PrinterDriverDll,
        Win32_PrinterSetting,
        Win32_PrinterShare,
        Win32_PrintJob,
        Win32_Processor,
        Win32_SCSIController,
        Win32_SCSIControllerDevice,
        Win32_SerialPort,
        Win32_SerialPortConfiguration,
        Win32_SerialPortSetting,
        Win32_SMBIOSMemory,
        Win32_SoundDevice,
        Win32_TapeDrive,
        Win32_TCPIPPrinterPort,
        Win32_USBController,
        Win32_USBControllerDevice,
        Win32_VideoController,
        Win32_VideoSettings,
        Win32_VoltageProbe,
    }
    /// <summary>
    /// 硬件信息字段
    /// </summary>
    public enum Win32_PnPEntitySection
    {
        Availability,                           //uint16   
        Caption,                                //string   
        ClassGuid,                              //string   
        CompatibleID,                         //string   
        ConfigManagerErrorCode,                 //uint32   
        ConfigManagerUserConfig,                //boolean  
        CreationClassName,                      //string   
        Description,                            //string   
        DeviceID,                               //string   
        ErrorCleared,                           //boolean  
        ErrorDescription,                       //string   
        HardwareID,                           //string   
        InstallDate,                            //datetime 
        LastErrorCode,                          //uint32   
        Manufacturer,                           //string   
        Name,                                   //string   
        PNPClass,                               //string   
        PNPDeviceID,                            //string   
        PowerManagementCapabilities,          //uint16   
        PowerManagementSupported,               //boolean  
        Present,                                //boolean  
        Service,                                //string   
        Status,                                 //string   
        StatusInfo,                             //uint16   
        SystemCreationClassName,                //string   
        SystemName,                             //string   
    };
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
"photon-server-sdk_v4-0-29-11263.exe" 是一款名为"Photon Server SDK" 的软件文件。Photon Server SDK 是由Exit Games公司开发的一套高性能的多人实时游戏服务器解决方案。 Photon Server SDK 定位于提供一个可靠、稳定和高效的多人游戏服务器引擎。它提供了一系列功能,使开发者能够轻松地构建和管理多人游戏。它支持多种平台和编程语言,包括Windows、Linux、iOS和Android,以及C++、C#、Unity和Netty等编程语言和引擎。 Photon Server SDK 的主要功能包括: 1. 提供可靠的服务器架构:它提供了高度可扩展的服务器架构,能够处理成千上万个并发连接。 2. 实时数据同步:它支持实时数据同步,使得多个玩家能够在游戏实时交互、同步游戏状态和数据。 3. 多人房间管理:它提供了强大的多人房间管理功能,使开发者能够创建、加入和管理多人游戏房间。 4. 客户端集成和网络通信:它提供了客户端集成的API和网络通信功能,使开发者能够轻松地与服务器通信,发送和接收游戏数据。 5. 实时聊天和语音通话功能:它支持实时聊天和语音通话功能,使玩家能够在游戏进行实时沟通。 总之,"photon-server-sdk_v4-0-29-11263.exe" 是一款功能强大的多人实时游戏服务器解决方案的安装文件。通过使用Photon Server SDK,开发者能够快速构建稳定、可扩展和高效的多人游戏服务器,并实现实时数据同步、多人房间管理和实时通信等功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值