When I try to get all running processes inside mouse event handler it throws an exception. First I thought that the problem persists because I put async
keyword before mouse event handler, but it was not the case, as the exception is thrown also for non-asynchronous methods.
I'm using MouseKeyHook library.
Exception message:
Additional information: Transition into COM context 0x1ac936a0 for this RuntimeCallableWrapper failed with the following error: An outgoing call cannot be made since the application is dispatching an input-synchronous call. (Exception from HRESULT: 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL)).
Event handler from which I'm getting all processes:
private async void MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
List<ProcessInfo> allRunningProcesses = Logic.GetAllProcesses();
// ...
}
Get all processes by using ManagementObjectSearcher
:
public static List<ProcessInfo> GetAllProcesses()
{
using (var searcher = new ManagementObjectSearcher(wmiQueryString))
using (var results = searcher.Get()) // EXCEPTION THROWN!
{
// ...
}
}
As you can see the exception is thrown when calling searcher.Get()
. Note: This method works without any issues if used outside the mouse event handler (MouseUp
).