1

I've created a windows service project that will use the TiffCP exe in order to split any tiff files its found into multiple tiff files. I'm using the code that was given as an example on the site:

public static class SplitTiffImage
{
    public static void Main()
    {
        string[] arguments =
        {
            @"Sample Data\multipage.tif,1",
            "SplitTiffImage_2ndPage.tif"
        };
        TiffCP.Program.Main(arguments);

        Process.Start("SplitTiffImage_2ndPage.tif");
    }
}

This works as expected and splits the file. However, a process is created (MSPVIEW.EXE) and I'm unable to access the file because it is being edited in another program. I have to manually kill the process to access it. I've also tried creating the process as a variable and then trying to close or kill it but that doesn't seem to be working either. Any ideas? Thanks.

Edit: I've put this code before accessing the process again and when the service stops and it seems to do the trick. It works but I'm wondering if there is a better way.

Process[] process = Process.GetProcessesByName("MSPVIEW");
if (process.Length > 0)
{
    foreach (var p in process)
    {
        p.Kill();
    }
}
DrivenTooFar
  • 110
  • 1
  • 1
  • 11

1 Answers1

1

Remove the

Process.Start("SplitTiffImage_2ndPage.tif");

from the code above.

The line opens the output in a default viewer. In your case it's Microsoft Office Document Imaging (MSPVIEW.EXE). You clearly don't need the output to be opened in a viewer.

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130
  • I had assumed that was necessary to split the image but I see that's not the case. Worked great, thanks for your help. – DrivenTooFar Mar 11 '16 at 13:05