上下文 0x3c74b38 已断开连接。不会使用代理来处理 COM 组件上的请求。

发布于 2024-09-10 13:33:29 字数 1185 浏览 0 评论 0原文

我正在 Microsoft Visual C# 2008 Express Edition 中开发一个窗口应用程序。在运行该应用程序时出现运行时错误。

string[] diskArray;
string driveNumber;
string driveLetter;

**searcher1 = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDiskToPartition");**
foreach (ManagementObject dm in searcher1.Get()) 
{
    diskArray = null;
    driveLetter = getValueInQuotes(dm["Dependent"].ToString());
    diskArray = getValueInQuotes(dm["Antecedent"].ToString()).Split(',');
    driveNumber = diskArray[0].Remove(0, 6).Trim();
    if(driveLetter==this._driveLetter)
    {
        /* This is where we get the drive serial */
        ManagementObjectSearcher disks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

        foreach (ManagementObject disk in disks.Get()) 
        {
            if (disk["Name"].ToString() == ("\\\\.\\PHYSICALDRIVE" + driveNumber) & disk["InterfaceType"].ToString() == "USB") {
                this._serialNumber = parseSerialFromDeviceID(disk["PNPDeviceID"].ToString());

(在突出显示的行中)

上下文 0x3c74b38 已断开连接。不会使用代理来处理 COM 组件上的请求。这可能会导致损坏或数据丢失。为了避免此问题,请确保所有上下文/单元都保持活动状态,直到应用程序完全完成使用表示其中存在的 COM 组件的 RuntimeCallableWrappers 为止。

I am developing a window application in Microsoft visual C # 2008 express edition.I get a run time error wen i run the application.

string[] diskArray;
string driveNumber;
string driveLetter;

**searcher1 = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDiskToPartition");**
foreach (ManagementObject dm in searcher1.Get()) 
{
    diskArray = null;
    driveLetter = getValueInQuotes(dm["Dependent"].ToString());
    diskArray = getValueInQuotes(dm["Antecedent"].ToString()).Split(',');
    driveNumber = diskArray[0].Remove(0, 6).Trim();
    if(driveLetter==this._driveLetter)
    {
        /* This is where we get the drive serial */
        ManagementObjectSearcher disks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

        foreach (ManagementObject disk in disks.Get()) 
        {
            if (disk["Name"].ToString() == ("\\\\.\\PHYSICALDRIVE" + driveNumber) & disk["InterfaceType"].ToString() == "USB") {
                this._serialNumber = parseSerialFromDeviceID(disk["PNPDeviceID"].ToString());

(in the highlighted line)

Context 0x3c74b38 is disconnected. No proxy will be used to service the request on the COM component. This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the application is completely done with the RuntimeCallableWrappers that represent COM components that live inside them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方的韩爷 2024-09-17 13:33:29

很可能,您可以在内部异常中找到另一个异常,例如,

COMException: The application called an interface that was marshalled for a different thread.

这意味着您必须在另一个线程中调用您的方法。如果您查看调用堆栈,您可能会发现调用此代码的事件处理程序。只需使用 调用/BeginInvoke 方法调用您的代码。请参阅下面的示例:

if (this.InvokeRequired) // in some cases this condition will not work
{
    this.BeginInvoke(new MethodInvoker(delegate() { this.Your_Method(); }));
    return;
}

当 USB 设备断开连接时,我遇到了类似的错误。但就我而言,我在自动生成的 WMI 包装类中得到了它,我在 LibUsbDotNet 事件处理程序中调用了该类。

Likely, you can find in the inner exceptions another one, e.g.

COMException: The application called an interface that was marshalled for a different thread.

That means you have to call your methods in another thread. Likely if you review the call stack you'll find an event handler what calls this code. Just use Invoke/BeginInvoke method to call your code. See example below:

if (this.InvokeRequired) // in some cases this condition will not work
{
    this.BeginInvoke(new MethodInvoker(delegate() { this.Your_Method(); }));
    return;
}

I got similar error when a USB device has been disconnected. But in my case I got it in autogenerated WMI wrap class which I called in LibUsbDotNet event handler.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文