Multiple documents send to default printer queue order
<p>I am developing an application which is work as print agent without getting user interaction. In there, I have to consider about below conditions.</p>

<ul>
<li>Download file shouldn't be access for user.</li>
<li>file sould be deleted after print it.</li>
<li>The download document could be either Image/PDF or word.docx</li>
<li>First downloaded file should be print first.</li>
</ul>

<p>So far I able to complete as follow.
 - watcher method created to catch up new download file.</p>

<pre><code>public void catchDocuments()
        {
            if (!string.IsNullOrEmpty(Program.docDirectory))
            {
                file_watcher = new FileSystemWatcher();
                file_watcher.Path = Program.docDirectory;
                file_watcher.EnableRaisingEvents = true;
                file_watcher.Created += new FileSystemEventHandler(OnChanged);
            }            
        }
</code></pre>

<p>when new file came, it will fire Onchange event and print document.</p>

<pre><code>string extension = Path.GetExtension(args.FullPath);
if (extension.Equals(@".png") || extension.Equals(@".jpeg") || extension.Equals(@".jpg"))
{
    docCtrl.imageToByteArray(nFile);
    docCtrl.printImage();
}
else if (extension.Equals(@".pdf"))
{                     
    docCtrl.PrintPDF(nFile);
}
</code></pre>

<p>But My problem is, When another files download before complete print process of downloaded file, Application will not work properly.  </p>

<p>I used print option as follow.</p>

<pre><code>//For Image printing
public void printImage()
{     
    System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
     pd.PrintPage += new PrintPageEventHandler(PrintPage);        
    PrintDialog pdi = new PrintDialog();
    pdi.Document = pd;
    pdi.PrinterSettings.PrinterName;
    pd.Print();    
}

    //For PDF Printing
public void PrintPDF(string path)
    {
       PrintDialog pdf = new PrintDialog();
       Process p = new Process();
       pdf.AllowSelection = true;
       pdf.AllowSomePages = true;
       p.EnableRaisingEvents = true; //Important line of code
       p.StartInfo = new ProcessStartInfo()
         {
           CreateNoWindow = true,
           Verb = "print",
           FileName = path,
         };
       p.Start();
       p.WaitForExit();
       p.Close();
    }
</code></pre>

<p>how could I overcome this issue. I'll be really appreciate your good thoughts.</p>