Windows Service for after Exception

2

Is there a way to make a Windows service created in do not give Stop() after Exception ?

The service was created with a timer , which will be executed every 1 hour, but there was an error in the execution and it returned a exception , so the problem is that when the time timer did not start.

Do you need to do any specific treatment on Catch ?

The section below is called when Timer is executed.

  

o TimerImport is another Timer

private void ExecutarServico()
{
    timerImportacao.Enabled = false;
    CarregarConfiguracoesServico();
    CadastroBusiness biz = new CadastroBusiness();
    try
    {
        if (GeraArquivosExportacao())
        {
            AlertaBusiness.RegistrarLogEventViewer("FEPWeb - Iniciando processo de Exportação.");

            ServicoFepWeb sfw = new ServicoFepWeb();
            sfw.UriInput = uriInput; sfw.DirInput = operServico.CaminhoSaida; sfw.UserCred = userCred; sfw.PassCred = passCred;
            biz.GerarDocumentoFepWeb(operServico.CaminhoSaida);
            sfw.SendFiles();

            if (biz.RetornoFepWeb.Count != 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (string str in biz.RetornoFepWeb.ToArray())
                    sb.Append(str + Environment.NewLine);
                biz.EnviarAlertaFepWebErro("Exportação FEPWeb.", MensagemBusiness.RetornaMensagens("Exportar_FepWeb_Aviso") + Environment.NewLine + sb.ToString(), operServico.DestinatarioMail);
            }
            AlertaBusiness.RegistrarLogEventViewer("Processo de Exportação FEPWeb, concluido com sucesso.");
        }
    }
    catch (Exception ex)
    {
        AlertaBusiness.RegistrarLogEventViewer(MensagemBusiness.RetornaMensagens("Exportar_FepWeb_ERR") + Environment.NewLine + ex.Message + Environment.NewLine + (ex.InnerException != null ? ex.InnerException.ToString() : String.Empty), EventLogEntryType.Error);
        biz.EnviarAlertaFepWebErro("Exportação FEPWeb.", MensagemBusiness.RetornaMensagens("Exportar_FepWeb_ERR") + Environment.NewLine + ex.Message + Environment.NewLine + (ex.InnerException != null ? ex.InnerException.ToString() : String.Empty), operServico.DestinatarioMail);
    }
    finally
    {
        timerImportacao.Enabled = true;
    }
}
    
asked by anonymous 17.11.2015 / 20:51

1 answer

0

Try to put a try {} inside your catch , the error may be being caused by it.

private void ExecutarServico()
{
    timerImportacao.Enabled = false;
    CarregarConfiguracoesServico();
    CadastroBusiness biz = new CadastroBusiness();
    try
    {
        if (GeraArquivosExportacao())
        {
            AlertaBusiness.RegistrarLogEventViewer("FEPWeb - Iniciando processo de Exportação.");

            ServicoFepWeb sfw = new ServicoFepWeb();
            sfw.UriInput = uriInput; sfw.DirInput = operServico.CaminhoSaida; sfw.UserCred = userCred; sfw.PassCred = passCred;
            biz.GerarDocumentoFepWeb(operServico.CaminhoSaida);
            sfw.SendFiles();

            if (biz.RetornoFepWeb.Count != 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (string str in biz.RetornoFepWeb.ToArray())
                    sb.Append(str + Environment.NewLine);
                biz.EnviarAlertaFepWebErro("Exportação FEPWeb.", MensagemBusiness.RetornaMensagens("Exportar_FepWeb_Aviso") + Environment.NewLine + sb.ToString(), operServico.DestinatarioMail);
            }
            AlertaBusiness.RegistrarLogEventViewer("Processo de Exportação FEPWeb, concluido com sucesso.");
        }
    }
    catch (Exception ex)
    {
        try {
            AlertaBusiness.RegistrarLogEventViewer(MensagemBusiness.RetornaMensagens("Exportar_FepWeb_ERR") + Environment.NewLine + ex.Message + Environment.NewLine + (ex.InnerException != null ? ex.InnerException.ToString() : String.Empty), EventLogEntryType.Error);
        biz.EnviarAlertaFepWebErro("Exportação FEPWeb.", MensagemBusiness.RetornaMensagens("Exportar_FepWeb_ERR") + Environment.NewLine + ex.Message + Environment.NewLine + (ex.InnerException != null ? ex.InnerException.ToString() : String.Empty), operServico.DestinatarioMail);
        } catch {
            ;
        }
    }
    finally
    {
        timerImportacao.Enabled = true;
    }
}
    
15.07.2016 / 07:06