Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 18 Microsoft’s Approach 1 –.NET Mobile Framework part 2 Rob Pooley
Programming Handheld and Mobile devices 2.NET The.NET Compact Framework is a subset of the.NET Framework. It consists of the base class libraries and has a few additional libraries that are specific to mobility and device development. The.NET Compact Framework runs on a high performance JIT Compiler. The Common Language Runtime (CLR) is built from the ground up to be specific to the.NET Compact Framework so that it runs more efficiently on small targeted devices that are limited in memory, resources, and must conserve battery power. To be able to run.NET Compact Framework applications, the targeted platforms must support the.NET Compact Framework runtime. –.NET Compact Framework requires a minimum of Windows CE.NET (Windows CE version 4.1 for the released version of the.NET Compact Framework) with two exceptions: Microsoft Pocket PC, Microsoft Pocket PC 2002, and Microsoft Pocket PC 2002 Phone Edition support the.NET Compact Framework.
Programming Handheld and Mobile devices 3 Structure
Programming Handheld and Mobile devices 4 Namespaces supported in.NET Framework and.NET Compact Framework
Programming Handheld and Mobile devices 5 Windows Forms All the common features Windows Forms in the.NET Framework are present in.NET Compact Framework. These features are differently implemented in a separate manner to make them more efficient for size and performance. Supported are: Common controls such as: –Buttons –Listboxes –Tree-views –Listviews –Combo boxes –Textboxes –Picture boxes –Scroll bars –Labels Bitmaps Pens Brushes Colors Drawing Fonts Support for Forms
Programming Handheld and Mobile devices 6 Networking with TCP etc. The System.Net.Sockets namespace is used to provide an interface to access the transport layer of protocol stacks. Multiple protocols can be exposed through this class. In addition,.NET Compact Framework provides additional classes that simplify common developer tasks encapsulating much of the necessary code that is common across all TCP client/server applications. Some of these are: –TCPListener –TCPClient –UDPClient
Programming Handheld and Mobile devices 7 HTTP HttpWebRequest and HttpWebResponse classes provide a rich HTTP client. These classes also support many of the standard mechanisms for encryption and authentication such as SSL/TLS and basic HTTP authentication. Other Web requests can be implemented using other protocols such as: –WebRequest interface –WebResponse interface –IwebRequestCreate interface
Programming Handheld and Mobile devices 8 System.Threading Namespace The System.Threading namespace provides classes and interfaces that enable multithreaded programming. In addition to classes for synchronizing thread activities and access to data (Mutex, Monitor, Interlocked, AutoResetEvent, and so on), this namespace includes aMutexMonitorInterlocked AutoResetEvent –ThreadPool class that allows you to use a pool of system-supplied threads, and aThreadPool –Timer class that executes callback methods on thread pool threads.Timer
Programming Handheld and Mobile devices 9 Threading using System; using System.Threading; // Simple threading scenario: Start a static method running // on a second thread. public class ThreadExample { // The ThreadProc method is called when the thread starts. // It loops ten times, writing to the console and yielding // the rest of its time slice each time, and then ends. public static void ThreadProc() { for (int i = 0; i < 10; i++) { Console.WriteLine("ThreadProc: {0}", i); // Yield the rest of the time slice. Thread.Sleep(0); } public static void Main() { Console.WriteLine("Main thread: Start a second thread."); // The constructor for the Thread class requires a ThreadStart // delegate that represents the method to be executed on the // thread. C# simplifies the creation of this delegate. Thread t = new Thread(new ThreadStart(ThreadProc)); // Start ThreadProc. On a uniprocessor, the thread does not get // any processor time until the main thread yields. Uncomment // the Thread.Sleep that follows t.Start() to see the difference. t.Start(); //Thread.Sleep(0); for (int i = 0; i < 4; i++) { Console.WriteLine("Main thread: Do some work."); Thread.Sleep(0); } Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends."); t.Join(); Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program."); Console.ReadLine(); }
Programming Handheld and Mobile devices 10.NET vs J2ME vs Palm OS Problems –Palm OS is the most cumbersome to program –Palm OS uses C/C++ –Palm OS and.NET Compact are both specific to certain kinds of device –J2ME requires a JVM (KVM or CVM) –J2ME is not really compatible with J2SE Benefits –Palm OS is available for many PDAs –J2ME is the most portable –J2ME has wireless features as standard –J2ME uses Java –.NET is higher level –.NET supports XML –.NET supports several languages