[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Window Service Crashed

Posted on 2014-01-06
6
Medium Priority
?
269 Views
Last Modified: 2014-01-14
Hi Expert,

I work on an existing window service to transfer PDFs to TIFs.
But if one pdf is empty. It will crash the window service. The program could not work on next pdf. And I could not delete it.

The WS could not work on next pdf until I deleted the problem pdf and restarted the WS.
I want to make WS fault tolerant. Please help! Appreciated!!


        private void Convert(string strInput)
        {
            Boolean blnSuccess = true;
            string strOutput = "";

            if (!File.Exists(strInput))
            {
                Log(enumLogLevel.Warning, "File not found: " + strInput);
                return;
            }

            try
            {
                strOutput = GenerateOutputFilename(strInput);

                switch (strConvertFromType)
                {
                    case "pdf":
                        ConvertPDFToImage(strInput, strOutput);
                        break;
                    default:
                        if (strConvertToType == "pdf")
                        {
                            CreatePDF(strInput, strOutput);
                        }
                        else
                        {
                            if (blnConvert1BPP == true)
                                ConvertImage1BPP(strInput, strOutput);
                            else
                                ConvertImage(strInput, strOutput);
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                blnSuccess = false;
                Log(enumLogLevel.Warning, "Error converting image: " + strInput + " - " + ex.Message);
            }

            if (blnSuccess && blnDeleteSourceFile)
            {
                try
                {
                    File.Delete(strInput);
                }
                catch (Exception ex)
                {
                    Log(enumLogLevel.Warning, "Error removing file: " + strInput + " - " + ex.Message);
                }
            }

            return;
        }

Open in new window

0
Comment
Question by:jssong2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:Korbus
ID: 39760705
What the last thing you Log() before it crashes?
0
 

Author Comment

by:jssong2000
ID: 39762076
Log(enumLogLevel.Warning, "File not found: " + strInput);


Thanks!!
0
 

Author Comment

by:jssong2000
ID: 39762105
Please see below and attachment for the whole process:

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace ImageConverterService
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
                  {
                        new ImageConverter()
                  };
            ServiceBase.Run(ServicesToRun);
        }
    }
}
ImageConverter.cs
0
 
LVL 10

Accepted Solution

by:
Korbus earned 1500 total points
ID: 39774987
Sorry about they delay responding.
So, just to make sure I unerstand correctly:
you have an empty (zero size?) file called say ... c:\test.pdf
you SEE this file in windows explorer before launching your software
but your software returns file not found, for File.Exists("c:\\test.pdf");
Is that correct?

(just tested this myself, created a zero length test.pdf, and File.Exists()  returned a TRUE value, indicating it DOES see the file. I did hard-code in the filename in my test.)

I've looked through your full code, though I do not have enough time to do any serious analysis of it, i DID notice that you are generating filenames, it's possible your error lies somwhere in here: an illegal filename character, or incorrectly formated filename/path.  Does that final log (from the file.exists section) show exatly the right filename?
0
 

Author Closing Comment

by:jssong2000
ID: 39780131
FileName is correct. It threw an exception when it's an empty file.
Modified to log the problem but continue process.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question