Reply to post: That C# code

'Just give me any old date and I'll make it work' ... said the VB script to the coder

Alien8n

That C# code

For some reason a previous employer wrote their own scanning software. It was created as a test project to see if it could be done with no intention of actually being used in a live environment. It very quickly became a live application, scanning batches of coupons and saving the scans in their own individual folders and storing a reference in a database so they were easy to find. The reference was a barcode on each coupon, associated with a campaign and a person. All worked fine, most batches could be upwards of 20 coupons and everything was hunky dory. Except for one client.

One client decided instead of a tear-off coupon, or a small complimentary slip sized coupon they'd have full sized A4 coupons. The scanner would fail after 8 or 9 scans. Because of the way the batches were processed they couldn't be split into smaller groups for scanning. They'd been having this issue for several month before it was decided to hand the issue to myself as a "learning exercise" to familiarise myself with C#. So I build in some logging into the code, as it runs it drops a line of text into a text file, the idea being the last line of text should give a clue as to what it's doing when it crashes.

It crashes at the same point each time, at the point it opens the scanned image and tries to save it. The exact same thing it's done over and over again for every other client's coupons. On the PC we run the code and turn on system monitoring and see a spike in memory usage at the same point it crashes.

Turns out it's saving the images into an array before saving to file and can't handle the memory usage. A quick re-write and it now scans and saves individual images. It still crashes. A final re-write and some extra code to garbage handle the now orphaned image memory and it's all fixed (and runs a lot quicker due to no longer hogging the PC's memory). For some reason, despite C# supposedly automatically handling memory allocation it wasn't doing so.

More worryingly for me was why the issue was allowed to continue, then get handed to a complete novice at C#, when they employed a team of 4 experienced developers. That said I could never understand why they were coding entire SQL queries into their code instead of passing parameters to a stored procedure.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon