Last post Jul 13, 2014 10:52 PM by Eileen ni - MSFT
Jul 10, 2014 09:19 AM|yashpalsharma|LINK
I have a requirement where I have to print 50 reports for the item whenever the item is scanned.
I scan item A and then a new thread is started to print the reports.
I scan item B and then again a new thread is started to print the reports.
I scan item C and then again a new thread is started to print the reports.
I scan item D and then again a new thread is started to print the reports.
Now what happens is, the sequence of printing the item reports is changing.
for example ,the item D reports are printing before item C.
Now I want the reports to be printed in exactly the same sequence in which they were scanned.
Jul 10, 2014 09:39 AM|AidyF|LINK
The order things are printed in is down to the print queue. I imagine you'd have to query the print queue to see if your document has been printed. This doesn't sound like an asp.net site though so it's probably outside the scope of this forum.
Jul 10, 2014 09:41 AM|csharpgreg|LINK
Hello Yashpalsharma. Thanks for your post!
When you multithread - using .NET Task Parallel Library - .NET will manage each thread and maximize the servers' cores to get the work done as fast as possible. This means that
you can't control the order in which threads get processed. So you can't print out the reports in order unless you single thread. Does this make sense?
Jul 13, 2014 10:52 PM|Eileen ni - MSFT|LINK
Thanks for your post.
As AidyF mentioned,This doesn't sound like an asp.net app.
If so,Try adding the items to a queue (for example,Queue<Item>) and have the BackgroundWorker process the queue.
Please check this:
C# Printing and Threading
and you can use
Hope this helps u.