Solved

Window Service Crashed

Posted on 2014-01-06
6
247 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
6 Comments
 
LVL 10

Expert Comment

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

Author Comment

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


Thanks!!
0
 

Author Comment

by:jssong2000
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
FileName is correct. It threw an exception when it's an empty file.
Modified to log the problem but continue process.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now