Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Desktop Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Search

XML Feeds

Google Ads

Tags: order

comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

Today I was trying to print a bunch of reports. The reports were supposed to come out in order because the are numbered.

You can do this in one report I hear you say… no because I use an old version of a reporting engine and that engine doesn’t really support multipage reports very well. You see I need to print a dutch version on one side and the french version on the other side. I could do this by printing all the dutch first and then feeding them back in and printing the french side, but dutch and french version need to have the same number obviously. Not so obvious if the printer has a hickup from time to time. But we now have a duplex printer so I just have to send out page 1 in dutch and then page 2 in french with the same number then page 3 dutch again with the following number. This is something my version of the reporting engine can’t handle but I had a quick fix. Making it print one page dutch and then a page french with the same number can be done in the same report. So I just send out n-times such a report with a changing number. Simple.

This seemed very easy and I had it printing all the reports in notime at all. But they came out in random order. It took me a while to remember how that came. I wrote the offending code a long time ago.

First I started by ordering the list I used. Then I started to debug the for each loop that prints all of them. And everything was fine.

Then I stumbled accross this.

I use the same reporting class for all my reporting. And the printreport method looks like this.

  1. Public Sub PrintReport(ByVal Dialog As Boolean) Implements Interfaces.INineraysReport.PrintReport
  2.             _Dialog = Dialog
  3.             _PrintThread.Start()
  4.         End Sub

Do you notice anything?

Yes it uses a thread. So my calling method did have the list sorted like it should have been but the thread messed everything up.

So I have to make it not use the thread for this. Or have the thread just wait for eachother which will give about the same result.

I guess the user will just have to wait until I send the reports to the printer.

So I changed it to this.

  1. Public Sub PrintReport(ByVal Dialog As Boolean, Optional ByVal UseThread As Boolean = True) Implements Interfaces.INineraysReport.PrintReport
  2.             _Dialog = Dialog
  3.             If UseThread Then
  4.                 _PrintThread.Start()
  5.             Else
  6.                 PrintReport()
  7.             End If
  8.         End Sub

PrintReport is a private method BTW that does all the hard work.

About the Author

User bio imageChristiaan is a forensic technician who programs on the side, although my function description says that I do IT-things for 90% of the time . I'm an avid VB.NET fan and I use lots of the ALT.Net techniques, like unit-testing, nhibernate, logging, IoC, ...
Social SitingsTwitterLinkedInHomePageLTD RSS Feed
793 views
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback