?
Solved

Window Service Crashed

Posted on 2014-01-06
6
Medium Priority
?
272 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
  • 3
  • 2
5 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 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