Solved

Window Service Crashed

Posted on 2014-01-06
6
261 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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

696 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