marți, 6 iulie 2010

Changing the location of My Documents in Windows CE

In this post I'll show you how to change the default location of the My Documents folder from the internal RAM to a flash disk location or SD card for your Windows CE device. This is mainly the case because Active Sync uses this folder to synchronize files with the device and initially, My Documents is located into a volatile memory region and all data saved there will be lost after a device reboot. Even worst is the fact that after the reboot, the synchronization process will erase all your files from the desktop PC as well.
So, in order to change the location of My Documents to the flash disk, open the Windows CE registry editor and open the key:
[HKEY_LOCAL_MACHINE\System\StorageManager\MSFLash]
and change the values of Folder and Name to "My Documents" ( without the quotes ).
Then choose to save your registry and reboot your device.
After the reboot, the Flash disk will appear renamed to "My Documents" and you can set-up a synchronized connection with the PC using Active Sync without having to loose the files every time you reboot.

marți, 13 aprilie 2010

Disposable generic list members

In this short post I will discuss about the necessity of calling Dispose on Disposable generic list members prior to remove them from the list.
Say you have a disposable type, e.g. MyDisposableType and create a generic list of such a type:

List myList = new List( );

Now, suppose that you use your list and at some point you need to remove one of the items using RemoveAt. With disposable types, the correct sequence should be:

myList[ itemIndex ].Dispose( );
myList.RemoveAt( itemIndex );

and this is because instances of non-disposed objects that are referred by MyDisposableType would still exist in memory after the object reference is removed from the list.
This is easy to verify using the .NET CF Remote Perfomance Monitor and taking GC Heap snapshots and monitoring the instance numbers of Disposable types referred by MyDisposableType.

joi, 4 februarie 2010

.NET CF Installed Version

In order for you to retrieve the current .NET Compact Framework installed on your Windows Mobile or Windows CE device, a simple thing to do is open the \Windows folder and execute cgacutil.exe. A dialog box will pop up stating the current version of Microsoft .NET Compact Framework ( e.g. [ 3.5.7283.0] ).
Cool!

marți, 26 ianuarie 2010

.NET CF Exceptions

My .NET CF application is throwing some wierd exceptions which I can see when executing it in debug mode.
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

These exceptions are thrown when the Image property is set:
myBtn.Image = ( (System.Drawing.Image) ( resources.GetObject( "myBtn.Image" ) ) );

It is confusing as the image is actually loaded and I can see it displayed on the control when I run the application. Apparently this is a bug of the .NET CF, which "slips" these execptions to the debugger, after it had actually handled them internally. People at Microsoft say it is safe to ignore these exceptions. Well, I've spent a couple of hours trying to figure it out before I found some hints here:

http://social.msdn.microsoft.com/forums/en-US/vssmartdevicesvbcs/thread/ac29e918-a966-44e8-910b-75c6cc12aabf/
It all became easier after this. Ignorance solves it all.