Threads, Timers, and Windows CE


Modern operating systems support multitasking and multithreading. Multitasking is the capability of the operating system to load many programs into memory simultaneously and share CPU time between the programs. In modern operating systems with memory protections , each task is set in its own virtual address space, which cannot be accessed by other tasks . This arrangement makes computers much more stable, but it also means that the cost of setting up a new, independent computing job as its own task is relatively expensive.

Multithreading is the capability of the operating system to support many independent units of execution in a single process. Each unit of execution is a thread, and each thread receives slices of CPU time. However, each thread occupies the same virtual address space. So, it is possible for one thread to interfere destructively with data used by another thread. However, setting up a new thread is far less expensive than setting up a whole new task, because no new address space is needed.

The .NET Compact Framework (CF) lets developers use the multithreading support available in the Windows CE operating system. However, there are some important limitations in Windows CE's support of multithreading that you should be aware of:

  • The maximum number of processes is 32. Thus, developers should be very stingy about spawning a whole new process if spinning a thread can do the same work.

  • Each process gets a maximum of 32MB of address space.

  • Although threads are less expensive than processes, .NET CF programmers should consider everything expensive. Creating too many new threads will harm performance. One way to mitigate this problem is to use thread pools, discussed later in this chapter in the "Managing Multiple Threads with a Thread Pool" section.

The .NET Compact Framework supports threads in two ways. The first is through a Thread object. Through the Thread object, developers can spawn, terminate, and pass messages between threads. The second way to simulate threading behavior is through the Timer , an object that is familiar to Visual Basic developers. We discuss both threads and timers in great detail in this chapter.



Microsoft.NET Compact Framework Kick Start
Microsoft .NET Compact Framework Kick Start
ISBN: 0672325705
EAN: 2147483647
Year: 2003
Pages: 206

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net