The .NET Compact Framework (CF) transformed Windows Mobile development by bringing managed code to mobile devices. Released in 2003, it enabled developers to use C# and VB.NET—languages they already knew—for PocketPC applications.
The Development Challenge
Before .NET CF, Windows Mobile developers faced difficult choices:
| Approach | Pros | Cons |
|---|---|---|
| eMbedded Visual C++ | Performance, API access | Memory management, complexity |
| eMbedded Visual Basic | Easier development | Slow, limited |
| Java (J2ME) | Cross-platform | Limited integration |
.NET CF offered a compelling middle ground: modern language features with acceptable performance.
Framework Architecture
.NET Compact Framework Stack:
┌────────────────────────────────────────�?
�? Your Application �?
├────────────────────────────────────────�?
�? Class Libraries (BCL subset) �?
�? ├── System.Windows.Forms �?
�? ├── System.Data (SQL CE) �?
�? ├── System.Xml �?
�? └── System.Net �?
├────────────────────────────────────────�?
�? Common Language Runtime (CLR) �?
�? └── JIT Compiler �?
├────────────────────────────────────────�?
�? Platform Adaptation Layer �?
├────────────────────────────────────────�?
�? Windows CE / Windows Mobile �?
└────────────────────────────────────────�?
Version History
| Version | Year | Key Features |
|---|---|---|
| 1.0 | 2003 | Initial release, Pocket PC 2003 |
| 2.0 | 2005 | Generics, Windows Mobile 5.0 |
| 3.5 | 2007 | LINQ, Windows Mobile 6.0 |
Each version expanded capabilities while maintaining device compatibility.
Development Environment
Visual Studio Integration
Starting with VS 2003, mobile development integrated into the main IDE:
- Device emulators for testing
- Remote debugging to physical devices
- Form designers for UI
- IntelliSense for framework classes
Project Types
// Device Application structure
namespace MyPocketPCApp
{
static class Program
{
[MTAThread]
static void Main()
{
Application.Run(new MainForm());
}
}
}
Framework Comparison
Available vs Desktop .NET
| Feature | Desktop .NET | .NET CF |
|---|---|---|
| Full BCL | Yes | ~30% subset |
| Windows Forms | Full | Subset |
| ADO.NET | Full | SQL CE focused |
| XML | Full | Core classes |
| Reflection | Full | Limited |
| Generics | 2.0+ | 2.0+ |
Memory Considerations
.NET CF targeted devices with limited resources:
// Memory-conscious patterns
// Dispose objects explicitly
using (SqlCeConnection conn = new SqlCeConnection(connectionString))
{
// Use connection
} // Disposed here
// Avoid large object allocations
// Use StringBuilder for string concatenation
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000; i++)
{
sb.Append(data[i]);
}
string result = sb.ToString();
User Interface Development
Windows Forms Subset
.NET CF provided familiar controls:
public class MainForm : Form
{
private Button btnAction;
private ListView listView;
private MainMenu mainMenu;
public MainForm()
{
// Initialize controls
this.btnAction = new Button();
this.btnAction.Text = "Action";
this.btnAction.Click += BtnAction_Click;
// Mobile-specific menu
this.mainMenu = new MainMenu();
MenuItem menuItem = new MenuItem();
menuItem.Text = "Options";
this.mainMenu.MenuItems.Add(menuItem);
this.Menu = this.mainMenu;
this.Controls.Add(btnAction);
}
private void BtnAction_Click(object sender, EventArgs e)
{
MessageBox.Show("Button clicked!");
}
}
Mobile-Specific Controls
- InputPanel: Soft keyboard integration
- MainMenu: Hardware button menus
- Notification: System tray integration
- HardwareButton: Device button mapping
Data Access
SQL Server Compact Edition
SQL CE provided local database functionality:
// SQL CE database operations
string connectionString = @"Data Source=\My Documents\mydb.sdf";
using (SqlCeConnection conn = new SqlCeConnection(connectionString))
{
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Customers";
SqlCeDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string name = reader.GetString(0);
// Process data
}
}
Synchronization with RDA
Remote Data Access synchronized with SQL Server:
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess();
rda.InternetUrl = "http://server/sqlce/sscesa35.dll";
rda.LocalConnectionString = @"Data Source=\local.sdf";
rda.Pull("LocalTable",
"SELECT * FROM ServerTable",
connectionString);
Performance Optimization
JIT Considerations
.NET CF used JIT compilation with constraints:
// Avoid in performance-critical code:
// - Excessive boxing/unboxing
// - Virtual method calls in tight loops
// - Large value type copies
// Prefer:
// - Simple types
// - Sealed classes where appropriate
// - Array access over enumerators
Native Interop
P/Invoke enabled native code calls:
// Calling native APIs
[DllImport("coredll.dll")]
private static extern int PlaySound(
string fileName,
IntPtr hModule,
int flags);
public static void PlayWaveFile(string path)
{
PlaySound(path, IntPtr.Zero, 0x20000);
}
Common Application Patterns
Settings Storage
// Application settings
public static class Settings
{
private static string settingsPath =
Path.Combine(
Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData),
"settings.xml");
public static void Save(AppSettings settings)
{
XmlSerializer serializer =
new XmlSerializer(typeof(AppSettings));
using (StreamWriter writer = new StreamWriter(settingsPath))
{
serializer.Serialize(writer, settings);
}
}
}
Background Processing
// Background thread pattern
private void StartBackgroundWork()
{
Thread worker = new Thread(new ThreadStart(DoWork));
worker.IsBackground = true;
worker.Start();
}
private void DoWork()
{
// Long-running operation
// Update UI on main thread
this.Invoke(new MethodInvoker(delegate
{
this.statusLabel.Text = "Complete";
}));
}
Migration from eVC++
Many developers migrated from eMbedded Visual C++:
Benefits
- Faster development cycles
- Automatic memory management
- Modern language features
- Better debugging
Tradeoffs
- Slightly larger memory footprint
- JIT compilation overhead
- Some native APIs unavailable
Legacy and Influence
.NET CF established patterns that continued:
- Xamarin inherited mobile .NET concepts
- Windows Phone used Silverlight (similar approach)
- MAUI continues cross-platform tradition
- Blazor Mobile echoes managed code mobile development