Select to view content in your preferred language

How to know if a service has been started

648
1
05-12-2010 06:01 AM
SebastienPelletier
Frequent Contributor
Hi ,

I want to dynamically add services in my map and before I would like to know if the service was started.

How to know if a service has been started ?

Thanks
0 Kudos
1 Reply
AvronPolakow
Occasional Contributor
Although this doesn't check in advance you can check if the service exists when you call the service.

You need to trap the error but the normal try/catch inline won't capture the error because the error generated is at the application level.

You have to capture the error at the Application Level

1 - Create a global in your XAML Page.cs to hold any error you with to pass eg:
public partial class MainPage : UserControl
{
   string _strUnhandledException = "";
  :
  :

2 - Where you are dynamically adding your layer preload the variable with any message you might wish to display eg:

         ArcGISTiledMapServiceLayer TiledLayer = new ArcGISTiledMapServiceLayer();    
         TiledLayer.ID  = larrValues[0];
         TiledLayer.Url = larrValues[1];

        _strUnhandledException = larrValues[0] + "\n" + larrValues[1];   // «««««««««
        MyMap.Layers.Add(TiledLayer);

3 - In the Application XAML App.xaml.cs go to the event:

     private void Application_UnhandledException

   // Change the code to the following:
   if (!System.Diagnostics.Debugger.IsAttached)
   {
    e.Handled = true;

    if (_strUnhandledException != "") {ReportCustomError(e);}    // « new line
    else
    {
     Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
    }
   }

4 - In the Application XAML App.xaml.cs add this function:
  private void ReportCustomError(ApplicationUnhandledExceptionEventArgs e)
  {
   try
   {
    string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
    errorMsg          = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");

    errorMsg  = "Application Unhandled Exception:"
                   + "\n***************************"
                   + "\n" + e.ToString()
                   + "\n" + _strUnhandledException
                   + "\n\n" + errorMsg;

     MessageBox.Show(errorMsg);
     _strUnhandledException = "";
     return;
   }
   catch (Exception)
   {
   }
  }
0 Kudos