上下文 0x3c74b38 已断开连接。不会使用代理来处理 COM 组件上的请求。
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很可能,您可以在内部异常中找到另一个异常,例如,
这意味着您必须在另一个线程中调用您的方法。如果您查看调用堆栈,您可能会发现调用此代码的事件处理程序。只需使用 调用/BeginInvoke 方法调用您的代码。请参阅下面的示例:
当 USB 设备断开连接时,我遇到了类似的错误。但就我而言,我在自动生成的 WMI 包装类中得到了它,我在 LibUsbDotNet 事件处理程序中调用了该类。
Likely, you can find in the inner exceptions another one, e.g.
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:
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.