Solved

Window Service Crashed

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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