.NET 2.0 Sample Applications (C# 2.0, 2006)

Version: 1.0 Author: Adrian Kosmaczewski Date: February 2006 Programming Languages: C# 2.0 Tools: Visual Studio 2005 Professional Edition (not tested with the Express editions!) Platforms: Windows Licence: Creative Commons Public Domain

I created these applications to illustrate some aspects about .NET 2.0:

  • adonet.zip: This application shows how to use several new features of ADO.NET 2.0: DataSet.RemotingFormat, Data providers API, and agnostic database access. It also contains an example of how to use the UpdateBatchSize property of the DbDataAdaptor class.
  • consoleapplication.zip: This application shows how to create a simple Console application, that uses another class library to perform its duties. It also contains an example of how to use “generic collections” in C#.
  • filesearch.zip: This application shows how to use the BackgroundWorker component in a Windows Forms application. It allows the user to search files in a hard drive, using a similar approach to “Google Desktop” or “Spotlight” on the Macintosh. It just scans the drive and adds the matching files to a list. It also contains an example of how to use anonymous, inline methods for event handling, and an example of how to use the Timer to handle asynchronous, timed events.
  • filesystemservice.zip: This application shows how to use the FileSystemWatcher component in a Windows Service application. When started, it logs changes to any directory (new files created, renamed and deleted) to a text log file. It also contains an example of how to use simple settings in the App.config file, and how to retrieve them in the code.
  • reflectiondemo.zip: This application shows how to use the Reflection capabilities of .NET to retrieve information about types during runtime, and how to use them and invoke methods in them.
  • stringappend.zip: This application shows why to avoid pure string concatenation, the performance penalty that it can create, and how to use the StringBuilder class instead.

About distributedapplication.zip: Definitely this is the most interesting app of all :) This application shows how to organize a Visual Studio 2005 solution, reflecting a basic layered architecture. It offers the following structure:

  1. Windows UI (ClickOnce Application)
  2. Web UI (WebAPP)
  3. Web Service Layer (DistWebService)
  4. BusinessLibrary
  5. Northwind Database

It also contains examples of:

  • How to integrate the Enterprise Library in a solution
  • How to group different projects in “Solution Folders”
  • How to use “#region” elements to group logical code sections
  • How to use a NotificationCenter (Observer Design Pattern) in a rich client application
  • How to use the Singleton Design Pattern to have only one instance of the NotificationCenter
  • How to integrate unit testing in projects (only available for Team editions of Visual Studio)
  • How to inherit forms in a Windows Forms applications
  • How to create web applications using the Multiview component

Note: You need Microsoft’s Enterprise Library 2.0 for this project, as well as a SQL Server 2005 Express installation (with the data schema provided in the solution).

Just download the files, unzip and follow the instructions in the “Readme.txt” file included (which sooner or later tells you to open the “sln” file with Visual Studio 2005). These applications can be used freely, but as usual, I’m not responsible of anything that might go wrong with them! Use them at your own risk (read the “Licence.txt” file included!). Have fun!