.net - Rolling your own message loop, any pitfalls? -
this question related this question exception handling. workaround found there consists of rolling own message loop.
so main method looks this:
[stathread] static void main() { // needed there'll exception thrown // application.run/application.doevents, instead of threadexception // event being raised. application.setunhandledexceptionmode(unhandledexceptionmode.throwexception); application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); form form = new mainform(); form.show(); // loop here keep app running if non-fatal exception caught. { try { application.doevents(); thread.sleep(100); } catch (exception ex) { exceptionhandler.consumeexception(ex); } } while (!form.isdisposed); }
what i'm wondering though, is safe/decent way replace more typical 'application.run(new mainform());', whether it's used exception handling or whatever else, or should stick using application.run?
on app that's in testing similar approach used both loading (splashscreen) , exception handling, , don't think has caused troubles (yet :-))
pitfall 1:
thread.sleep(100);
never. use waitmessage().
otherwise, possible roll out own message loop, in scenario seems pointless.
you may want examine application.run() code (with .net reflector, instance).
Comments
Post a Comment