I have a general question about WndProc. I am trying to detect when hardware has changed on a workstation, I have all of this working, but I am trying to refresh the GUI when this happens. I call a method from WndProc that then does some other API calls
and WMI querys. Everytime I call the method from the below statement I get a failure from WMI.
<div style="background-color:white; color:black
<pre> <span style="color:blue protected <span style="color:blue override <span style="color:blue void WndProc(<span style="color:blue ref Message m)
{
Int32 DBT_DEVICEREMOVECOMPLETE = 0x8004;
Int32 DBT_DEVICEARRIVAL = 0x8000;
Int32 DBT_DEVNODES_CHANGED = 0x0007;
Int32 WM_DEVICECHANGE = 0x0219;
<span style="color:blue if (m.Msg == WM_DEVICECHANGE)
{
<span style="color:blue if (m.WParam.ToInt32() == DBT_DEVICEARRIVAL || m.WParam.ToInt32() == DBT_DEVICEREMOVECOMPLETE)
{
<span style="color:blue if (m.LParam.ToInt32() > 0)
{
<span style="color:blue if (cHardwareControl.TranslateWMDEVICEMessage(m.LParam, sDeviceChangeIgnoreList))
{
RefreshDeviceList(); <span style="color:green //THIS IS THE FAILURE POINT
}
}
}
}
<span style="color:blue base.WndProc(<span style="color:blue ref m);
}
[/code]
Inside my RefreshDeviceList() method I am calling WMI. Here is the error from WMI:
<pre>Context 0x2de710 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.[/code]
If I continue with the MDA error, this is what is caught in my try catch:
<pre>The application called an interface that was marshalled for a different thread.[/code]
Does anyone have any ideas on what is causing this?
Thanks in advanced.
View the full article
and WMI querys. Everytime I call the method from the below statement I get a failure from WMI.
<div style="background-color:white; color:black
<pre> <span style="color:blue protected <span style="color:blue override <span style="color:blue void WndProc(<span style="color:blue ref Message m)
{
Int32 DBT_DEVICEREMOVECOMPLETE = 0x8004;
Int32 DBT_DEVICEARRIVAL = 0x8000;
Int32 DBT_DEVNODES_CHANGED = 0x0007;
Int32 WM_DEVICECHANGE = 0x0219;
<span style="color:blue if (m.Msg == WM_DEVICECHANGE)
{
<span style="color:blue if (m.WParam.ToInt32() == DBT_DEVICEARRIVAL || m.WParam.ToInt32() == DBT_DEVICEREMOVECOMPLETE)
{
<span style="color:blue if (m.LParam.ToInt32() > 0)
{
<span style="color:blue if (cHardwareControl.TranslateWMDEVICEMessage(m.LParam, sDeviceChangeIgnoreList))
{
RefreshDeviceList(); <span style="color:green //THIS IS THE FAILURE POINT
}
}
}
}
<span style="color:blue base.WndProc(<span style="color:blue ref m);
}
[/code]
Inside my RefreshDeviceList() method I am calling WMI. Here is the error from WMI:
<pre>Context 0x2de710 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.[/code]
If I continue with the MDA error, this is what is caught in my try catch:
<pre>The application called an interface that was marshalled for a different thread.[/code]
Does anyone have any ideas on what is causing this?
Thanks in advanced.
View the full article