I have an application and I want to check through a Task if the user opens other applications and in that case minimize my application (but I can still use it for that purpose).
The problem is that it throws an exception
System.InvalidOperationException: 'El subproceso que realiza la llamada no puede obtener acceso a este objeto porque el propietario es otro subproceso.'
I understand that being in a subprocess can not manage the main process, but I do not know how to solve it.
Task checkProcess = new Task(() =>
{
if( Process.GetProcesses().Count() > numOfProcess)
WindowState = WindowState.Minimized;
});
checkProcess.Start();