0

I have this process to print a pdf to a printer. My intention is that after the process completes, the file should be moved to a done folder.

However, right now I am getting a file is being used by another process error.

I have tried setting a longer waitforexit timer and checking if the file is being used but it still fails.

This is the process and move function

public string Process(string FilePath, string PrinterName)
{
    Process p = new Process();
    p.StartInfo = new ProcessStartInfo()
    {
        CreateNoWindow = true,
        Verb = "printTo",
        FileName = FilePath,
        Arguments = PrinterName
    };
    p.Start();

    if (!p.WaitForExit(5000)) 
    {
        p.Close();
        p.Dispose();
        p.Kill();
    }

    return FilePath;
}

Print process in the main program

print.Process(pol[i].FilePath, pol[i].PrinterDriver);
System.IO.File.Move(pol[i].FilePath, Input + "\\Done");
JianYA
  • 2,750
  • 8
  • 60
  • 136

0 Answers0