What’s New in Visual Studio 2008 and the .NET Compact Framework 3.5

What’s New in Visual Studio 2008 and the .NET Compact Framework 3.5

ith the release of Visual Studio 2008, Microsoft has also updated the .NET Compact Framework. Unlike its desktop counterpart, there is no version 3.0 of the .NET Compact Framework. Instead, to align with the .NET Framework versioning on the desktop, the latest version of the .NET Compact Framework is now 3.5, up from its previous version number of 2.0.

The .NET Compact Framework 3.5 adds new APIs and, most notably, it now supports the new Language Integrated Query (LINQ) and Windows Communication Foundation (WCF) features that are standard on the .NET Framework (the WCF feature will be covered in more depth in an upcoming article). On the Visual Studio 2008 front, there are new tools to make testing and development work much easier and robust.

Language Integrated Query (LINQ)
One of the key changes in the .NET Compact Framework is the support for Language Integrated Query (LINQ). LINQ allows you to manipulate data just like you manipulate database records using a query language like SQL. So, instead of writing complex iterative loops to retrieve the data that you desire, you can just specify the data you want declaratively using LINQ and the compiler will do all the work for you.

While .NET Compact Framework 3.5 supports LINQ, some features supported in the .NET Framework are missing, specifically they are:

  • On the .NET Compact Framework, only standard query operators are supported. LINQ to DataSet is supported, which provides LINQ support for DataSet and DataTable.
  • On the .NET Compact Framework, LINQ to XML is supported except for XPath extensions.

To understand the usefulness of LINQ, suppose you have an array of type string that contains a list of names:

        Dim AllNames As String() = _           {"Jeffrey", "Kirby", "Gabriel", "Philip", "Ross", "Adam", _            "Alston", "Warren"}

Suppose you need to print out all the names in this array that start with the letter “G”. In this case, you can set up a loop and iteratively perform a comparison on each name. Things start to get more complex when you have more complicated filtering rules. Using LINQ, you could specify the filter using the From clause, like this:

        Dim FoundNames As IEnumerable(Of String) = _           From Name In AllNames Where Name.StartsWith("G")

When this statement has been executed, FoundNames will contain a collection of names that start with the letter “G”. It this case, it returns “Gabriel”. You can now add the names to a ListBox control, for example:

        For Each PeopleName In FoundNames            ListBox1.Items.Add(PeopleName)        Next

You can also use a more complex filter, such as the following:

        Dim FoundNames As IEnumerable(Of String) = _           From Name In AllNames Where Name.StartsWith("G") Or _           Name.Contains("by") _           Order By Name

In this case, FoundNames will now contain “Gabriel, Kirby”. Note that result is also sorted.

Another useful application of LINQ is in manipulating Windows Forms controls. Suppose you have a large number of controls on your form and you want to uncheck all the CheckBox controls without setting each individually. You can use the following code to do that using LINQ:

        '---retrieve all the checkbox controls in the current form---        Dim checkboxes As IEnumerable = _           From ctrl In Me.Controls Where TypeOf ctrl Is CheckBox        '---uncheck all the CheckBox controls---        For Each c As CheckBox In checkboxes            c.Checked = False        Next

Besides manipulating data in memory, LINQ can also be used to query data stored in structures like datasets and datatables. The following example (in C#) shows how the Employees table within the Northwind.sdf sample database is loaded onto a Dataset object and then queried using LINQ (see Listing 1).

If you want to query the employees based on their hire dates, use the following:

            emp = from employee in ds.Tables[0].AsEnumerable()                  where employee.Field("Hire Date").Year>1992                  select employee;            dataGrid1.DataSource = emp.AsDataView();

Another very cool capability of LINQ is its ability to manipulate XML documents. For example, if you want to create an XML document by hand, you can use the code segment shown in Listing 2.

Notice that the indentation gives you an overall visualization of the document structure. Alternatively, the code in Listing 2 can be rewritten much more clearly in Visual Studio 2008 (only in VB projects):

      Dim library As XElement = _                                                Professional Windows Vista Gadgets Programming                    Wrox                                                    ASP.NET 2.0 - A Developer's Notebook                     O'Reilly                                                    .NET 2.0 Networking Projects                    Apress                                                    Windows XP Unwired                    O'Reilly                            

To save the XML document to file, use the Save() method:

        library.Save("Books.xml")To perform querying on the XML document, load the document from file and then use LINQ:        Dim LibraryBooks As New XDocument        LibraryBooks = XDocument.Load("Books.xml")        Dim OReillyBooks As IEnumerable = _           From b In LibraryBooks.Descendants("Book") _           Where b.Element("Publisher") = "O'Reilly" _           Select b.Element("Title").Value        For Each book In OReillyBooks            Console.WriteLine(book)        Next

The above code will generate the following output:

ASP.NET 2.0 - A Developer's NotebookWindows XP Unwired

New APIs
In .NET Compact Framework 3.5, you can now programmatically retrieve the platform information (PocketPC or Smartphone) using the Platform property:

        '---need to import Microsoft.WindowsCE.Forms.dll---        Dim instance As Microsoft.WindowsCE.Forms.WinCEPlatform        instance = Microsoft.WindowsCE.Forms.SystemSettings.Platform()        MsgBox(instance.ToString)

You can also check the version number of the OS used in the device using the OSVersion property from the OperatingSystem class, like this:

        Dim OS As OperatingSystem        OS = Environment.OSVersion        MsgBox(OS.ToString)

If you need to play a sound file, .NET CF 3.5 includes the new SoundPlayer class, which allows you to play a .wav file:

Dim soundplayer As New Media.SoundPlayer        With soundplayer            .SoundLocation = "WindowsAlarm1.wav"            .Play()        End With

In addition, you can also play standard system sounds, like this:

        Media.SystemSounds.Asterisk.Play()        Media.SystemSounds.Beep.Play()        Media.SystemSounds.Exclamation.Play()        Media.SystemSounds.Hand.Play()        Media.SystemSounds.Question.Play()

The compression classes available in the desktop version of the .NET Framework is now finally available in .NET CF 3.5. The compression algorithms supported are GZip and Deflat. The following shows how you can use the new classes to perform compression and decompression.

First, ensure that you import the required namespaces:

Imports System.IOImports System.IO.Compression

The Compress() function shown in Listing 3, allows you to compress a byte() array and returns the compressed data in another byte array.

Because you do not know the actual size of the decompressed data, you have to progressively increase the size of the data array used to store the decompressed data. The dataBlock parameter suggests the number of bytes to copy at a time. A good rule of thumb is to use the size of the compressed data as the block size, such as:

'---data is the array containing the compressed data---dc_data = ExtractBytesFromStream(zipStream, data.Length):

The actual act of extracting the bytes from a stream object is accomplished by the helper ExtractBytesFromStream() function (Listing 4).

To test the functions defined above, use the following statements:

        Dim str As String = "Hello world"        Dim compressed_data As Byte()        '---compress the data---        compressed_data = _           Compress(System.Text.ASCIIEncoding.ASCII.GetBytes(str))        '---decompress the data---        Dim decompressed_data As Byte()        decompressed_data = Decompress(compressed_data)        '---print out the decompressed data---        MsgBox(System.Text.ASCIIEncoding.ASCII.GetString( _           decompressed_data, 0, decompressed_data.Length))

Configuration Tools
Concurrent with Visual Studio 2008’s release, Microsoft has also released the “Power Toys for .NET Compact Framework 3.5,” a set of tools to help .NET CF developers evaluate their applications’ performances, configurations, and diagnostics. Click here to download the PowerToys.

One useful tool included is the App Configuration Tool (NetCFCfg.exe), which is located in the default installation folder: C:Program FilesMicrosoft.NETSDKCompactFrameworkv3.5WindowsCEwce500. Within this folder are several folders targeting different processor types (see Figure 1).

Figure 1. The App Configuration Tool: Folders containing the App Configuration Tool for the different processor type.
Figure 2. Four Available Tabs: The various tabs in the Application Configuration Tool.

Select the processor that your Windows Mobile device uses and copy the folder into the device (via ActiveSync). Within your Windows Mobile device, navigate to the folder just copied, and then launch the NetCFCfg.exe application. Figure 2 shows the four tabs available:

  • About: This tab shows the versions of the .NET Compact Framework currently installed on your device and the version of your Windows Mobile OS.
  • GAC: This tab shows the list of assemblies installed in the Global Assembly Cache.
  • Device Policy: This tab allows you to configure all unconfigured applications to use a particular version of the .NET CF.
  • Application Policy: This tab allows you to individually configure each application to use a particular version of the .NET CF.

.NET Compact Framework CLR Profiler
Another tool that ships with the PowerToys is the .NET CF CLR Profiler, an adaption of the desktop version of the CLR profiler for .NET applications. Using this CLR profiler, you can look into the details on how your application is allocating and using managed objects.

Launch the .NET CF CLR Profiler tool from: Start | Programs | .NET Compact Framework PowerToys 3.5 | .NET CF CLR Profiler. When launched, click on the Start Application? (see Figure 3) button to launch an application that you want to profile.

Figure 3. The Start Application Button: This button launches an application that you want to profile.
Figure 4. Specify the Device: Choosing a device and the application to profile.

You will then be asked to specify the device that your application runs on and the path to the executable (see Figure 4) and any optional parameters that you want to pass into the application.

As the application runs, you can view the Heap Graph, which shows the various threads and its associated memory allocation (see Figure 5).

To stop the application that is currently being profiled, click the Kill Application button. A summary form showing the various statistics will be displayed (see Figure 6).

Figure 5. The Heap Graph: The .NET CF CLR Profiler in action.
Figure 6. Statistics Summary: A summary form showing the various statistics.

Explaining the use of the .NET CF CLR Profiler is beyond the scope of this article. For more information, check out the following posts by Steven Pratschner:

Figure 7. The Remote Performance Monitor: This tool displays a window showing the various parameters that it is monitoring real-time.

Remote Performance Monitor
Besides monitoring memory allocations of your applications, you can also monitor their performances of applications using the Remote Performance Monitor. The Remote Performance Monitor tool is also part of PowerToys and can be launched from: Start | Programs | .NET Compact Framework PowerToys 3.5 | Remote Performance Monitor. As with the CLR Profiler, you first launch the application that you want to monitor and then the tool displays a window showing the various parameters that it is monitoring in real time (see Figure 7).

A Quick Overview
Now you’ve got a quick overview of the new and important features available in the .NET Compact Framework 3.5 and the new tools shipped with Visual Studio 2008. Stay tuned for future articles that will dive into each topic in more details


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist