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.