TemperNTC Class Library - Update
Just to let you know, I updated the TemperNTC Class Library article and the class library with a fix to the issue with the external sensor's sometimes unreliable initialization. Now it works splendid everytime you access the device.
![]() | Source code and tester application in C# for .Net Framework 2.0 |
CRC32 Checksum Calculator
I'm working on the new version of my backup software where I need to calculate checksums on sizable files. It's going to be optional but obviously it should run as fast as possible, so I decided to implement CRC32 for it. Must be simpler, therefore much faster than MD5 hash computing, right? Nope...
| File size | CRC32 | MD5 |
|---|---|---|
| 4 MB | 0.059 s | 0.015 s |
| 182 MB | 2.756 s | 0.873 s |
| 1.8 GB | 26.320 s | 6.642 s |
I got these results on my Intel E6750 (C2D 2.66 GHz) and I surely optimized the heck out of my calculator which was based on Jeff Atwood's ASP code and uses a lookup table. I don't know what kind of magic the guys in Redmond have done, but the MD5 function in the .Net Framework 4.0 is insanely fast. On the other hand, BufferedStream is significantly slower than doing the stream reading on your own; on the largest 1.8 GB file it increased the runtime to 33 seconds.
My conclusion is, unless you work only with smaller files (under 50 MB) or you must keep the checksum value short, you're better off using the MD5 function and deal with the bigger hash size. In any other case feel free to grab my class and use it, it's great for shorter, real world content.
![]() | Source code in C# for .Net Framework 2.0 |
Hungarian Dictionary
Yay, I've been published! No it's not a book, it's my first Windows Phone application that went live on the Marketplace. That's one giant leap for me, one small step for mankind. :-) It's an English-Hungarian and German-Hungarian dictionary which works from a locally stored database. Select the dictionary type you need, then just start typing your word and it will filter the results for you on the fly. Tap on a word to see its translations in detail, you can even add it to your favorites. Check out the screenshots as they pretty much speak for themselves (although they are hard to hear in this size) then I will tell you about the challenges I had with this project.

First of all, I got my phone a few weeks ago and I haven't had any experience with the OS before. Let alone writing an application in Silverlight which was new to me, however it's not all that different from what I'm working with on a daily basis: ASP.NET and Windows.Forms but still, it needed some adjustment. I started with watching the superb WP7 Jump Start videos of Rob Miles and Andy Wigley, they are very cool chaps and I can say, very efficient teachers.
I was thinking what I should do as a learning project and this dictionary just felt right for this platform from every angle. I've created its predecessor in 2009 for Windows Mobile 5.0, it was a dinky little PDA application for my own use, but the most important part of it, the dictionary database files were done so I didn't need to put energy into that, I could start with basically rewriting the dictionary handler class to make it a bit more efficient and use internal caching for the search as you type method I was about to build into this new app.
Then I had to bite the silver bullet with creating a user friendly GUI that embraces the Metro design language, respecting the user's theme settings of dark / light background and chosen accent color, but still look good and having visible graphic buttons in each case. First I was thinking of using a panoramic layout but as it turned out the pivot layout is a better choice for the app's needs.
I ran into some problems and bugs, too... Silverlight has a ListBox control which was a great choice for the job of displaying search results, first it was all fine and dandy, especially in the emulator. But running the first version on my actual device revealed that my dictionary searching is blazing fast, but then the system keeps waiting for the ListBox control's shockingly slow rendering to finish. Alright, starting over, let's create my own ListBox control that actually works with more than 5 list items... Frankly I expected a bit better performance from the standard one. Then I had to deal with the shortcomings of my solution, two dynamically generated TextBlock controls in a StackPanel for each word, with click detection, hosting the whole bunch in a ScrollViewer... At least it's way faster. Obviously, pivot panning and list scrolling shouldn't register as unintended item selection. And it shouldn't be scrollable if there is no need to scroll due to the small number of items displayed. This issue might be solved in Mango, the emulator doesn't scroll, but on the current OS release it sure does. Anyway, it was great fun to work out all these issues.
I was almost ready when I decided that beside the Search, Translations and About pages I will add a Favorites & History handler page. I'm glad I did, it turned out to be a very cool feature, but my application already handled the Deactivated - Activated states and it kept crashing away when I tried to come back to the Favorites page from Tombstoning. Only one 3rd party application can run in the same time, when the app is not active due to running some other program that takes the screen away, my app practically gets killed (this is called Tombstoning), then it will get reloaded if you get back to it. It could reactivate on the other pages, but not on Favorites. It's becoming a known error, with 3 pivot pages it's perfect, but if you have 4 (or more) then on the third page reactivation will be fatal if you try to select your active pivot page in the OnNavigatedTo event handler, where it would be perfect because you couldn't see the first page popping in for a moment. Bit daft... Hopefully it will get fixed someday.
At this point I already had localized text on the user interface, showing Hungarian text if that's the selected system language, it will be supported by Mango so I can prepare for it. But there is a way to localize the application title and tile title too, so in order to make the app as good as it could be, I solved this issue, I even made a tool to help with this task in the future. And since I was there, I added the ability of selecting the user's own default language, even before the Hungarian language gets supported in the system.
Cherry on top of the sundae, I created the Windows Phone version of Moonbase, my class library of reusable functions helping out with often needed stuff like localization, file management in isolated storage, Style / Brush / Font selection, theme detection and whatnot. It will come handy in my next app.
Go and check out the app if you need such a thing, or just try it out for the fun of it; it's free!
![]() | Windows Phone Marketplace website |
If you're not familiar with Windows Phone, take a glimpse at its look and feel... Lovely, isn't it?
WP7 AppResLib DLL Generator
Nice title, I know... Chances are you won't be interested in this, but someone dropping by from Google or Bing will be grateful for what I offer here. As it happens, I couldn't let my shiny new gadget feel alienated, so I paid off the Microsoft Tax and registered as an official Windows Phone developer, which allowed me to unlock my phone for building applications for it and even do live debugging. I already finished my first app and I have some general best practices to share with you about localization.
My application supports English and Hungarian languages, there is a localization solution in the framework but I didn't use it, I went with a WP7 version of my own that I use in ASP.NET applications. It works from an XML file where each string has a name like ModuleTitle and an arbitrary number of child nodes with language code names (en, da, hu etc) and localized content strings. It doesn't matter here, you solve it any way you want. However, there is only one way to localize the Application Title (in the application list) and Tile Title (when you pin it to the home screen) and it's not exactly easy.
In short, you need a resource-only DLL file for each language you want to localize your application for, with two Title strings in each. Generating these resource-only DLL files is quite annoying, especially that you have to do all this typing and renaming all the time whenever you need to make changes, so I made a little tool that does it for you. It works from a project configuration XML file you create with the supported languages and localized strings, which will be inserted into a DLL template file I made without any debug information and 32 characters long placeholders for both Title strings. Just check out the downloaded tool's files, it has a readme, a sample project xml file you can edit and a list of Microsoft assigned Locale IDs you need to use.
After generating the DLL files, copy them into the root directory of your project and add them. The normal AppResLib.dll is the language neutral version, the MUI files are the localized versions. Make sure you open Properties on each of these and set the Build Action as Content so it will be included in your project properly. They will be copied into the XAP file on build, but you need to refer to these resources to actually use them. Open the project properties and see below how you need to set it up:

As you can see, you have to set the Application Title as @AppResLib.dll,-100 and the Tile Title as @AppResLib.dll,-200 where the numbers are strictly set resource IDs. Sure you can enter these into your WMAppManifest.xml file which you will need to edit anyway before you would release your app.
What you also must set is the Neutral Language of your application. Normally this will be English so you have to set it as plain English, not 'English (United States)' or what have you. If you don't follow this to the letter, you won't see any problem while testing your app, but you will get this error message when the App Hub processes your app's XAP file while uploading it to the Marketplace:
The [NeutralResourceLanguage] attribute is missing on the entry assembly. (2003)
With all these done, your app will work like a charm with the locales you support. If you don't support eg. Italian, you don't have to include the DLL for that language with English titles, in my app I included only the Neutral, US-English and Hungarian files and it's all fine that way. As I see the phone will use the US-English version as a fallback setting if you select a locale you don't support, the Neutral goes unused. Enjoy the generator, I hope it will make your professional life a bit easier.
Update: I had a little oversight in localization. I went for my own string translation solution which is fine, but if you want your application appear in the Marketplace with localized metadata for the supported languages, you must go with the standard localizaton method as well, otherwise you can enter the metadata (description, keywords, images, screenshots) only on the app's neutral language. In my case all I needed was creating a new Resource file for the main project, naming it AppResources.resx (neutral language), then another one named AppResources.hu-HU.resx. I put a test string in each, closed the project, opened the project's .csproj file and entered hu-HU into the SupportedCultures XML node. After this, when I uploaded an updated binary to the Marketplace, it allowed me to enter metadata for both supported languages. It's possible that this last entry on its own controls the supported languages in the Marketplace, but it's not something I want to experiment with.
![]() | Resource DLL generator for Windows Phone application title localization. Requires .Net Framework 4.0 |
TemperNTC Class Library
A few days ago I got a package from Hong Kong – my order from USB Fever, a TemperNTC USB thermometer with a remote sensor. I must say they have a very friendly customer service. My postal address in Hungary contains an á character in the street name which caused an encoding problem in their order confirmation email, so I wrote them about it to make sure it gets printed on the package label properly, or at least they could change it to an a. It was by night here and by the time I woke up, I got a reassuring reply with a photo of the package label, proving it's all fine on their end.

I want to use it for temperature logging and I'm glad I originally planned making my own device handler and logger software because the provided HidTemperNTC software is... quite Chinese, so I'm not terribly disappointed. It's okay for playing around, but absolutely unusable for what it was made for: logging. I won't go into details here, I don't want to bash the developers too much but attention to details and dogfooding should be part of their development process for sure.
It was a bit of a surprise that it has two thermometer sensors, an internal one in the USB device and the remote one at the end of the cable. The product description was a bit misleading I guess and I had a bit of a trouble reading the remote sensor, but at the end I managed it. Just like most of those who tried to do something with it, I use the HidFTDll.dll file's exported functions for the general device handling. While the function reading the internal sensor returns a temperature value in Celsius degrees, the remote sensor is not so easy: it requires a current voltage reading from the remote sensor called NTC and involves some mathematical witchcraft with an NTC lookup table. You don't want to know, just call my GetOuterTemperature() function and remember, ignorance is bliss.
The class library doesn't use more than .Net Framework 2.0 functionality and runs perfectly on
Basically this is all you have to do if you want to make this device work:
TemperNtc temper = new TemperNtc(true);
double inner = temper.GetInnerTemperature();
double outer = temper.GetOuterTemperature();
Update: The issue with the false outer temperature reading has been fixed, now it works reliably everytime you access the device. However, this still stands: if any of the sensors return an invalid value, it will return 1000 Celsius degrees, so you just have to ignore that reading.
Now that it's done, I can work on my temperature logger application that probably I will make available for anybody, when it's ready. Have fun with the class library!
![]() | Source code and tester application in C# for .Net Framework 2.0 |










