Since I started using Windows Vista the comfort when using my scanner has greatly decreased. The scanner is an HP 3770 and HP only offers pre-Vista software for it. I always liked the HP scanning application a lot (only the scanning program itself, not the dozen other applications that come with it) since it allowed me to scan multiple pages right after each other and then save them in one go. It even allows you to save all scanned pages to a PDF document if you have Adobe Acrobat installed. It also had support for certain filters, such as descreening. The default Vista scanning application is a lot simpler, but not bad at all. I really don't need any fancy features, but the one thing I do need is the ability to scan multiple pages without saving one page and then restarting the application - it is just so annoying. I also don't scan a lot, but a few weeks ago some multi page scans did come together and I was really annoyed. And what do you do if you are annoyed with a problem and the available software doesn't work? - right, you write your own!
Most current scanning software uses Windows Image Acquisition to communicate with the scanner. That's what I did as well. I used the WIA Automation Layer, an easy to use COM library, which deals with all the lower level stuff for you. All you have to do is connect to a scanner by showing the WIA device selection dialog or by searching for it using its GUID and then make a call to the device.Items[1].Transfer() method and that's it. So I wrapped this and some scanner properties in a class of my own and built a UI around it.
So far so good, but I must say that I was a little shocked when I saw that the UI froze during the scanning process even though I was invoking the Transfer() method asynchronously. The it occurred to me that by default all Windows Application projects created with Visual Studio have the STAThread (single-threaded apartment) attribute applied to their Main method. I'm not a COM expert, but from what I understand this means that a certain COM object only executes on a single thread. If a method is invoked from another thread the call is passed to the object through a standard window message in the queue of the appropriate thread. That thread is my main application thread.
One way to overcome this is to run in a multi-threaded apartment, which does solve the blocking of the UI, but causes the save file dialog to no longer work. This left me with three options: either stay in a MTA and find an alternative to the SaveFileDialog, find another way to execute the scanning process asynchronously or simply accept the blocked UI, because the first two options are too much work for a simple application that I write mostly for my own use. As you can imagine, I went with the latter - it's a simple scanning program and changing something in the UI while it's scanning doesn't make sense anyway (I know that this isn't the proper way to do it, but I don't intend to distribute this application that widely anyway).
I already said that I liked the idea of directly saving multiple pages to PDF, the only problem is, I don't own Adobe Acrobat, but I still thought that this would be a cool feature. Since there are dozens of free PDF libraries out there it wasn't a big problem either. I took a look at some of them and in the end went with PDFSharp and with just a few lines of code I could save scans as PDF documents.
If you are interested in trying out this little scanning application that I simply named after its purpose (that is conveniently scanning multiple pages) MultiScan, or if you want to take a look at the source code, here are the download links: (The program also works on Windows XP SP1 and beyond)
Binary (332 kb)
Source Code (441 kb)
On the right you can see a screenshot. The UI is very simplistic. One thing that might be a little un-intuitive is that after you've pressed "New Scan" and made your selection in the preview pane, you have to click "Accept Selection". This will save the selection to a temporary file and add it to your scanned page collection. This will not make the scanner start scanning again, it will just copy the selected area of the already scanned preview image to a temporary file. The preview image is scanned in full quality, thus it would be a waste of time to start up the scanner again for the final image. Once you have scanned all the pages you want, you can choose to save your work as either PNG, JPEG, BMP, Multi-page TIFF or PDF.