Export (0) Print
Expand All

Threading in the .NET Compact Framework

The .NET Compact Framework supports core threading functionality but does not support the following features in the full .NET Framework:

  • Access to the compressed stack on the current thread.

  • The managed representation of the Win32 OVERLAPPED structure.

  • Classes that manage the execution context.

  • Using semaphores.

  • Thread-state attributes.

  • Most wait handle operations except for getting the handle.

The .NET Compact Framework supports using the ThreadStart delegate for use with the System.Threading.Thread.Start method and using TimerCallback delegate with a Timer.

The .NET Compact Framework version 2.0 supports specifying time-out parameters for the following threading methods:

Changes in Thread Pools

In the .NET Compact Framework version 1.0, the default maximum number of threads in a thread pool is 256 with a stack size of 64K. In version 2.0, this is reduced to a maximum of 25 with a stack size of 128K, which more closely matches the functionality of the full (desktop) .NET Framework.

An HTTP request will fail and throw an exception if no thread is available in the thread pool. The main exceptions in this situation are the following.

Exception Condition

OutOfMemoryException

Unable to queue the user's callback.

WebException

Not enough threads in the thread pool to complete the operation.

You can avoid running out of threads by reducing the number of concurrent Web requests, or by increasing the maximum allowed threads in the thread pool. The .NET Compact Framework version 2.0 supports the SetMaxThreads method. Specify its parameters as follows:

Parameter Description

workerThreads

The maximum number of worker threads in the thread pool. This can be any value.

completionPortThreads

The maximum number of asynchronous threads in the thread pool. The .NET Compact Framework currently ignores this value, but it must be set between 1 and 1,000. For future compatibility, 500 is recommended because it is the default value for the full .NET Framework.

For devices running .NET Compact Framework version 1.0, you can decrease the maximum allowed threads in the thread pool by changing a registry setting. Set MaxThreads in CFROOT\ThreadPool key to the desired value. Note that this registry key is not used by the .NET Compact Framework version 2.0.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft