Re: REPOST: Suppressing the default "Unexpected Error" dialog OR global error handler - CF 2.0

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Daniel Moth (dmoth74_at_hotmail.com)
Date: 08/01/04


Date: Sun, 1 Aug 2004 19:40:37 +0100

So I run my tests against the CF 2.0 (VS2005 Beta 1)

1. As before try..catch around main catches the exceptions on the GUI thread

2. As before exceptions on background threads result in the ugly built-in
dialog popping up BUT IN ADDITION after hitting the Quit button on the
dialog, *our* exception catch code also runs(!)

3. Exceptions that occur in the Control.Invoked code do not freeze/lock the
app [I really wish this bug gets fixed for CF 1.0 SP3 too]. Instead the
behaviour is identical to case 2.

So for CF 1.0, unless the bug of case 3 gets fixed, you should not wrap main
in a try..catch

For CF 2.0, one hopes that cases 2 & 3 can be altered to only run our code
and not show the built in dialog (hence make it as case 1).

Ideally though there should be parity with the desktop version in this area
and the AppDomain.UnhandledException event implemented...

Feel free to add you own comments

Cheers
Daniel

"Daniel Moth" <dmoth74@hotmail.com> wrote in message
news:OXyXNU4ZEHA.808@tk2msftngp13.phx.gbl...
> Attached is a zip that proves how relying on try..catch around
> Application.Run is a bad idea... Tested with CF 1.0 SP2 and SP3... Let me
> know if I am missing something...
>
> If global error handling is not in the plans for CF 2.0 then please at
least
> give us a way to suppress the Microsoft dialog in our apps...
>
>
> >>> Original post from 7 Oct 2003 follows
>
> Hi
>
> When an error occurs we get the helpful dialog with the exe name as the
> title and text starting with "Error An unexpected error has occurred in
> <filename.exe>. Select Quit and then restart this program or select
Details
> for more information."
>
> The above is fine for debug builds but we don't want this for release
builds
> out in the field. In fact, the above box keeps my gui thread (e.g.
> Forms.Timers) running and hence prevents our watch dog from resetting the
> unit! In any case, we should be able to either suppress the box completely
> or at least catch any exception in a central place and deal with it
> ourselves (own box or just Exit).
>
> I have experimented with try catching Application.Run and there are 3
> behaviours I have come across:
> 1. If the exception is thrown *directly* in the GUI thread, e.g.
> button_click then the try catch works great; problem solved
> 2. If the exception occurs in a background thread then the try catch is
> ignored and the unwanted dialog pops up
> 3. If the exception occurs in the GUI thread as a result of a
Control.Invoke
> then the app freezes/locks up!
>
> Is there a workaround or at least plans to support some solution
> (Application.ThreadException perhaps?) in a future CF release?
>
> Cheers
> Daniel
>
>
>
>



Relevant Pages

  • Re: Update GUI from RunWorkerCompleted
    ... Should i use the RunWorkerCompleted event for this purpose? ... As Marc said, the RunWorkerCompleted event should be raised on the GUI thread, just as you expected it to. ... As far as your specific problem goes: if you're getting a cross-thread exception from code that's actually being executed from the RunWorkerCompleted event, that strongly suggets that the UI object you're using somehow got created on a different thread, or that the BackgroundWorker was for some reason not created on the UI thread. ... But the fact is, if you're getting that exception, there's some mistake somewhere in how these things are being set up. ...
    (microsoft.public.dotnet.languages.csharp)
  • GUI Thread - Is cross-thread operation really bad?
    ... I had always been advised that doing a cross-thread operation on a GUI thread is not safe and should be avoided. ... void InitializeComponent() ... // simulate long running task ... Yes, it will throw exception when running inside IDE/debugger, but if I run it alone, it will just run - no exception thrown. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Catch outofmemory exception
    ... > There ain't no such creature. ... > Exception), but it is a profoundly bad idea to try it. ... OutOfMemoryError can occur in your GUI thread and then you're stuck. ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Re: COMException and Multiple Threads
    ... > My VB.NET application spins up a secondary GUI thread. ... > while generating this exception, both the main and secondary GUI threads ... I can find no explanation for why the main thread should halt ...
    (microsoft.public.dotnet.framework)
  • Re: Application xxx has encountered a serious error and must shut
    ... Chris Tacke, Embedded MVP ... use of Queueacross multiple threads - and even my exception ... stopped my Serial port thread - last time it stopped the whole app:-O. ... NB I replaced the MS SerialPort with OpenNetCF Serial and this seems ...
    (microsoft.public.windowsce.app.development)