Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5991253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:21:37+00:00 2026-05-22T23:21:37+00:00

I need to handle exception in Application_UnhandledException event of App.xaml.cs file. I am getting

  • 0

I need to handle exception in Application_UnhandledException event of App.xaml.cs file. I am getting the Exception object using e.ExceptionObject. Now, I need to send the exception details to my server using WCF service with the help of WebClient.

Whenever I send request to WCF service using WebClient, it send the request but the callback event e.g. webClient_UploadStringCompleted never gets executed. I read that the exceptions are handled in separate thread etc.

What I have already tried, but not succeeded:

  1. ThreadStart
  2. Thread
  3. App.Current.RootVisual.Dispatcher.BeginInvoke
  4. RootFrame.Dispatcher.BeginInvoke
  5. System.Windows.Deployment.Current.Dispatcher.BeginInvoke
  6. Deployment.Current.Dispatcher.BeginInvoke

Can anybody tell, how to send the error details from Application_UnhandledException to WCF service with WebClient?

Code:

// Code to execute on Unhandled Exceptions

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{

e.Handled = true;

// Option 1
Thread thread = new Thread(() => MainPage.HandleException(e.ExceptionObject));
thread.Start();
ThreadStart start = new ThreadStart(NonUIWork);

// Option 2
Thread thread = new Thread(start);
thread.Start(e.ExceptionObject);

// Option 3
Deployment.Current.Dispatcher.BeginInvoke(delegate { MainPage.HandleException(e.ExceptionObject); }); 

// Option 4
App.Current.RootVisual.Dispatcher.BeginInvoke(MainPage.HandleException, e.ExceptionObject);

// Option 5
RootFrame.Dispatcher.BeginInvoke(() => { MainPage.HandleException(e.ExceptionObject); });

// Option 6
MainPage.HandleException(e.ExceptionObject); 
}

In MainPage.HandleException method, I am sending exception details to WCF service with WebClient object. But, the call back function of WebClient (webClient_UploadStringCompleted) never gets executed. It seems that the thread in which the Application_UnhandledException event is executed is getting suspended immedietely.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:21:38+00:00Added an answer on May 22, 2026 at 11:21 pm

    Yes, this can’t work by design. The event is raised while the CLR is shutting down the AppDomain, just before it gets unloaded. You cannot expect any thread or asynchronous operation to run to completion. All your code must be done by the time your event handler exits. Be sure to use synchronous methods and avoid using threads all together. There isn’t any point in the usual don’t-block-the-UI code, there is no UI anymore by the time the event is raised.

    This is indeed an issue on Windows Phone, it doesn’t have the synchronous methods of WebClient, like WebClient.UploadString(). You’ll have to make UploadStringAsync() synchronous yourself by using an AutoResetEvent. Call its WaitOne() method after the upload call, call its Set() method in the callback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to identify who raise an exception to handle better str error, is
I need to handle strings in my php script using regular expressions. But there
For a project I need to handle audio in an iPhone app quite special
I'm using IIS7 and ASP.NET. Basically building a simple CMS and need to handle
I need to handle the ORA-01400 error (cannot insert NULL into (SCHEMA.TABLE_NAME.COLUMN_NAME) ) using
I have a winforms app, and I need to access the Handle property of
I need to handle events of two different types but I'm running into the
I'm writing a batch (.bat) script and I need to handle the case in
I have a problem with NCurses ... i need to handle all keys like
I am writing a search engine (why not hey?) and need to handle navigating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.