开发者

COM Exception Receiving WMI Event in MMC Snapin

开发者 https://www.devze.com 2022-12-12 00:52 出处:网络
I am attempting to create an MMC snapin that among other things, will receive and display log events that are fired from my service.I have created the watcher and it fires correctly, but when I try to

I am attempting to create an MMC snapin that among other things, will receive and display log events that are fired from my service. I have created the watcher and it fires correctly, but when I try to add nodes to my MmcListView, I am getting a COMException which says "COM object that has been separated from its underlying RCW cannot be used."

Here is the code in question:

private void LogEvent_EventArrived(object sender, EventArrivedEventArgs e)
{
    LogEvent logEvent = new LogEvent(e.NewEvent);
    if (SnapIn.InvokeRequired)
    {
        object[] args = new object[] { logEvent };
        SnapIn.Invoke(new ManagementAction(Add开发者_Go百科Event), args);
    }
    else
        AddEvent(logEvent);
}

The LogEvent class is a simple class which does the work of converting the ManagmentBaseObject properties to type safe properties which are easily coded against. The AddEvent method does the actual work of adding the LogEvent object to the ResultNodes list of the MmcListView.

The Exception I mentioned is actually called on the SECOND event being fired, and seems to happen on the call to InvokeRequired. I have no idea what is actually going on here. Any ideas?


OK, this was incredibly stupid... but the reality was that the method I was calling via Invoke was throwing an exception, and it wasn't bubbling up as expected to the caller, and instead was showing as the weird COM exception. Once I cleared up the exception in the method I was calling via delegate, everything worked fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号