I'm using a message filter to control authorization in my winform application. My (simplified) code is something like this:
public bool PreFilterMessage(ref Message m)
{
if(IsAllowed())
return true;
throw new UnauthorizedAccessException();
}
But after throwing the exception, the same message keeps coming back, causing an infinite loop.
Is it possible to throw exception inside PreFilterMessage?
PreFilterMessage catches all events that happen, and that likely includes the event that gets triggered when you close the exception thrown at you.
So, your PreFilterMessage either returns true (and thus the event gets ignored) or it throws an exception. That doesn't look like intended behavior.