| I have an application that I have built and is just sort of printing app. First I populate ListBox and format it then goto c:\somefolder in some folder are pdf files it looks on listbox and see if there is any file name that matches an item on the listbox and sends it to the default printer.Everything is working great ,but say I have JohnDoe.pdf,ShahRukh.pdf,Vijay.pdf how can I make it to send the files in that order, for now it works great ,but I want to be able to print ==> JohnDoe.pdf first, then ShahRukh.pdf and so on and so forth.Please if you have any idea to spare is much welcome. Thanks in advance. This what I have right now it works great but print all items that match but randomly .I want it to respond or print matches in order of occurrence from top to bottom.This my code that does it but it just prints randomly any ideas. |
{
try
{
string dir = @"C:\slim\slimyyyy";//GOTO this directory ["C:||"==> and look for a folder called "WHAT---EVER"
if (Directory.Exists(dir))//If a directory defined above exists then do the followings
{
string[] pdf_specFiles = Directory.GetFiles(dir);
if (pdf_specFiles.Length > 0)
{
foreach (object item in listBox1.Items)
// foreach (object line in rchTxtContent.Lines)
{
foreach (string file in pdf_specFiles)
{
string fileName = Path.GetFileName(file);
if (fileName == item.ToString())
{
PrintDocument(Path.GetFullPath(file));
}
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex);
}
}

Ekona PikinPosted Mar 5, 2015, 7:34 PM
VulpesPosted Mar 5, 2015, 6:47 PM
So I think you therefore have to put the delay in the Click event handler.
I'd see if it improves matters if you increase it from 0.5 to 1.0 second.
Ekona PikinPosted Mar 5, 2015, 6:14 PM
VulpesPosted Mar 5, 2015, 4:39 PM
Ekona PikinPosted Mar 5, 2015, 12:31 PM
// Process proc = new Process();
ProcessStartInfo stackOverflowHelp = new ProcessStartInfo();
stackOverflowHelp.Verb = "print";
stackOverflowHelp.FileName = pdfFileName;
stackOverflowHelp.CreateNoWindow = true;
stackOverflowHelp.WindowStyle = ProcessWindowStyle.Hidden;
Process gamingBoy = new Process();
gamingBoy.StartInfo = stackOverflowHelp;
gamingBoy.Start();
gamingBoy.WaitForInputIdle();
if (gamingBoy.HasExited == false)
{
gamingBoy.WaitForExit(100);
//return true;
}
// System.Threading.Thread.Sleep(1000);
gamingBoy.EnableRaisingEvents = true;
gamingBoy.Close();
// return true;
//proc.Close();
//KillAdobe("AcroRd32");
return true;
}
catch
{
return false;
}
}
VulpesPosted Mar 5, 2015, 12:24 PM
If you are then it might account for the random behavior as you can't necessarily control the order in which the threads are given CPU time.
Ekona PikinPosted Mar 5, 2015, 12:15 PM
VulpesPosted Mar 5, 2015, 12:04 PM
You're iterating through the listbox items in the order they appear, then iterating through the files in the directory and printing the file when you find a match. On the face of it, you'd therefore expect that the files would be printed in the order they appear in the listbox.
The only thing I can think of is that your PrintDocument method is not causing the file to be printed straightaway but is instead queuing the files to be printed in such a way that they are not necessarily printed in the order they were added to the queue. This might happen, for example, if different priorities were assigned to different files.
Does any of that ring any alarm bells?
Ekona PikinPosted Mar 5, 2015, 11:17 AM
VulpesPosted Mar 5, 2015, 9:07 AM