440 likes | 960 Views
Compact Framework .NETcf : from the trenches. casey chesnut brains-N-brawn.com 12/13/2004. Questions. Language C#, VB .NET, C++, Java At work .NET, .NETcf Windows CE Questions are encouraged throughout the presentation. Experience. Pervasive / Seamless Computing
E N D
Compact Framework.NETcf : from the trenches casey chesnut brains-N-brawn.com 12/13/2004
Questions • Language • C#, VB .NET, C++, Java • At work • .NET, .NETcf • Windows CE • Questions are encouraged throughout the presentation
Experience • Pervasive / Seamless Computing • Web Services (ASMX, WSE) • Mobility (CF, Tablet) • Speech (Speech .NET, SAPI) • Location Based Services (MapPoint, GPS) • Security • Artificial Intelligence
Compact Framework • MapPoint .NET Client • LBS – GPS, MapPoint, SQL NS, MSN Mess. • Signature Biometric • Speech Recognition – DIME & SAPI WS • Managed DirectPlay Wrapper for PPC • ASP.NET-like Web Service server • Port of a 75K –> 100K line WS app • ~20 web services, ~175 web methods • Cryptography • Client-side WSE 2.0 and WS-* • Barcode Image Reader • Custom Speech Recognition • Custom Text-To-Speech
Agenda • [ Platform Ahead CF Chapter ] • [ /cfWSE article(s)? ] • What is missing • How to get it back • Where we are now • Futures • Resources
What Is Missing • Assemblies • Namespaces • Types • Events • Properties • Methods • Overloads • Behavior
.NETfx versus .NETcf System.Web System.WinForms Services UI Design ComponentModel Description HtmlControls Discovery WebControls System.Drawing Protocols Caching Security Drawing2D Printing Text Configuration SessionState Imaging System.Data System.Xml ADO.NET SqlClient XmlDocument Serialization Reader/Writers Design SqlServerCe Xslt/XPath System Collections IO Configuration Runtime InteropServices * Security Net ServiceProcess Remoting Text Reflection * Diagnostics Serialization Globalization Resources * Threading
Metrics * Beta 1 Numbers for all assemblies
Examples • Typed DataSets (.xsd) • Resource files (.resx) • Hardcoded strings • Registry keys • Environment variables • File paths • Types • Sealed • Partial implementations • Controls
Examples • pInvoke • Unicode • MarshalAs • FieldOffset • Missing or different DLLs • Missing or different OS features • WMI • Hosts • Updating controls from thread • Bugs
How To Get It Back • Open source efforts • 3rd party controls • OS • pInvoke CE .NET Win32 APIs • eVC++ thunk layer • Write the logic yourself
Open Source • OpenNETCF.org • Smart Device Framework v1.2 July 15, 2004 • Pocket PC Magazine Award Winner • Complementary to .NETcf • Adds missing functionality that desktop has • Adds functionality specific to devices • e.g. 15 controls with designer support • Visual Studio .NET Integration • Be aware of license
Open Source • go-mono.org • “Effort to create an open source implementation of .NET” • Not intended for CE • Platform independence is slow • Be aware of licensing • ssCli / Rotor • MS initiative • Academic licensing only • Port to CE .NET underway
3rd party controls • Franson GpsTools • /n Software’s IP*Works for CF • Field Software PrinterCE.NetCF • Odyssey CfCom • InstallShield Developer Mobile Edition • Preemptive Dotfuscator • ComponentOne Studio for CF • Xceed Zip for .NETcf • IntelliProg UI controls • HP thumbprint biometric
OS (pInvoke) • VB .NET cannot do unsafe • Call C# library if necessary • Only 32-bit blittable types • Pass by ref • Strings • unicode only, use StringBuilder • No callbacks from native code • MessageWindow • Make blocking call into native code
OS (pInvoke) • coredll.dll has 1600 functions • Cannot handle nested structures • Flatten into byte arrays • Manually marshal • Managed pointers • DLLImport CE & XP pattern for keeping common codebase • Native thunking layers • e.g. CF -> eVC++ -> COM
.NETcf extended System.Web System.WinForms Services UI Design ComponentModel Description HtmlControls Discovery WebControls System.Drawing Protocols Caching Security Drawing2D Printing Text Configuration SessionState Imaging System.Data System.Xml ADO.NET SqlClient XmlDocument Serialization Reader/Writers Design SqlServerCe Xslt/XPath System Collections IO Configuration Runtime InteropServices * Security Net ServiceProcess Remoting Text Reflection * Diagnostics Serialization Globalization Resources * Threading
Development • .NETcf support in VS.NET • Supplement with eVC++ tools • Can do command line builds • Ports of nUnit to run on a device • Use ethernet for debugging • Class Library Comparison Tool • Windows Mobile Developer Power Toys
Emulator • Same image as run on device • 80% speed of device • Newer emulators can do GAPI • eVC++ can share folders • Can sometimes active sync • Cannot listen • Ultimately need a slew of devices
Debugging • System.SR.dll • OutputDebugString • No console • TraceListeners • No event log (to file) • Use the device • Cannot attach to process • Cannot skip to next statement • Cannot do mixed native and managed • Native threads will not break
Debugging (pInvoke) • Cross platform pInvoke signatures • SetLastError, Marshal.GetLastWin32Error • Exceptions • NotSupportedException • MissingMethodException • Look at .h files • dumpbin /exports (name mangling) • P/Invoke Wizard, pInvoke.net
Data • Web Services • SQL CE • XML • DB API • Pocket Access • CSV • 3rd party
SQL CE • Connected – Sql Server • Disconnected – SQL CE • Merge Replication • No concurrent access • Basic SQL support • No stored procedures • Runs in process • Can become corrupted
Communication • Web Services • Sockets • System.IRDA • OpenNetCF Phone • OpenNetCF Bluetooth • OpenNetCF Wi-Fi • NO Remoting
Garbage Collection • Not generational • Mark and sweep aggressive • Compacting is rare • Code pitching has never happened when i was watching • pInvoke memory leaks • Platform builder / cordbg • mscoree.stat
Performance • Tech Preview was interpreted • Machine code is generated (but not much) • 2 JITs (ARM & other), No NGEN • ARM is supposed to be twice as fast • UI is ~20% slower on device • Release builds are slower? • No profiling tools • Environment.TickCount • QueryPerformanceCounter • SP2 has some significant resource and xml handling speed ups
What is slow • XmlDocument • Reflection • Catching Exceptions • pInvoke • DataSets • Web Services • Data Binding
What is faster • XmlDocument – XmlTextReader / Writer • Reflection – pre generate code • Catching Exceptions – only exceptions • pInvoke – wrap into native thunk layer • DataSets – SQL CE • Web Services – call from a thread • Data Binding – bind manually
What is faster • SQL CE replication • Pre-init behind the scenes • Re-use objects • StringBuilder • Drawing controls top-down, parents 1st • Don’t overdesign
Final Thought • Stages of a Mobile Developer • I can’t do anything! • Nevermind, everything I need is here, I just need to do some work to access it. • Why is this so slow? • Maybe I should optimize my code … • Remember that these are resource constrained Devices! • Remember that these are resource constrained Devices!
Futures • Smartphones • CF v2.0 • SQL Mobile • Future Windows Mobile Platform • To watch • Predictions
SmartPhone • 2002 OS does NOT support .NETcf • No future support announced by MS • 2003 Windows Mobile • 2nd edition release happening in US • will run CF v1 but not CF v2 (PPC will) • .NETcf is basically unchanged • Missing some UI controls • Missing SQL Server CE • 1-hand usage / no touch screen
CF v2.0 • eVC IDE integrated into VS .NET • Mixed native and managed debugging • Remote tools • Attach to running process • Language updates • Generics, Iterators, Anonymous methods • Performance • Execution engine, Unified JIT, profiling(?) • Interop • COM RCW, Marshalling, Runtime hosting(?)
CF v2.0 • WinForms • Docking, Anchoring, Tabbing, Auto-scroll, Clipboard, Extend existing types, Multi-resolution • Controls • WebBrowser, DateTimePicker, MonthCalendar, LinkLabel, Notification Balloon, DocList, RichInk, Splitter, DataContainer, UserControl, HelpProvider
CF v2.0 • Emulator • ActiveSync, Shared Folder, Stateful, Orientations • Protocols • IPv6, Kerberos, NTLM, SOAP 1.2 • XML • XPath(?), Schemas, Serialization • BCL • Image, Messaging, Registry, Cryptography, Serial, Sound
SQL Mobile • Multiple Connections • Improved Performance • Greatly Improved Tool Support • SqlCeResultSet • Bulk loads • Cursor • The desktop does not get this • Runs on Tablet PCs too • Fixes 2.0 corruption bug
Future Windows Mobile Platform • Enhanced services and device support • Mobile Outlook • SMS Messaging • Telephony • Notifications Broker • Location Services • Peripherals support • Device Configuration • Direct3D, DirectDraw • Distributed through SDKs
To watch • Portable Media Center • Has .NETcf v1.0 on it (closed) • SPOT watches • 384K RAM, ~1 meg flash, 27Mhz • OS = HAL + CLR • Only what is needed • Interpreted • .netcpu • For .NET embedded platforms • New form factors • Motorola MPx • Mappoint Location Services • WS Device Profile (UPnP 2.0)
Predictions • HREF EXEs (CAS?) • Car .NET • Longhorn • Modular
Resources • Newsgroups (microsoft.public.) • dotnet.framework.compactframework • smartphone.developer • Portals • msdn.microsoft.com/smartclient/understanding/netcf/ • pocketpcdn.com • devbuzz.com • codeproject.com/netcf/ • microsoft.com/seminar/events/series/msdnmobility.mspx • brains-N-brawn.com/cfBCL/ • Spelunking • Reflector, ILDasm
Books • .NET Compact Framework (MS Press) C# • .NET Compact Framework Kick Start (Sams) C# & VB • Definitive Guide to the .NETcf (Apress) VB • SQL Server CE Database Development with .NETcf (APress) C# & VB • Building Solutions with the .NETcf (Addison) VB • .NET Compact Framework Programming (Addison) C# or VB