首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

急待,Mobile下面要开一个线程,有API吗

2012-01-19 
急急急急急!在线等待,Mobile下面要开一个线程,有API吗?在Win32下面,可有用_beginthreadex(),那么Mobile下

急急急急急!在线等待,Mobile下面要开一个线程,有API吗?
在Win32下面,可有用_beginthreadex(),那么Mobile下面类似的API吗?

[解决办法]
CreateThread
https://msdn2.microsoft.com/en-us/library/bb202727.aspx

Requirements: Windows Mobile Version 5.0 and later
[解决办法]
同楼上。
[解决办法]
This function creates a thread to execute within the address space of the calling process. 

HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes, 
DWORD dwStackSize, 
LPTHREAD_START_ROUTINE lpStartAddress, 
LPVOID lpParameter, 
DWORD dwCreationFlags, 
LPDWORD lpThreadId
); 
Parameters
lpThreadAttributes 
[in] Ignored. Must be NULL. 
dwStackSize 
[in] Ignored unless the STACK_SIZE_PARAM_IS_A_RESERVATION flag is used. In which case the dwStackSize parameter specifies the virtual memory reserved for the new thread. When ignored, the default stack size for a thread is determined by the linker setting /STACK. 
lpStartAddress 
[in] Long pointer to the application-defined function of type LPTHREAD_START_ROUTINE to be executed by the thread and represents the starting address of the thread. For more information on the thread function, see ThreadProc. 
lpParameter 
[in] Long pointer to a single 32-bit parameter value passed to the thread. 
dwCreationFlags 
[in] Specifies flags that control the creation of the thread. The following table shows the valid flags. Value Description 
CREATE_SUSPENDED The thread is created in a suspended state and will not run until the ResumeThread function is called. The thread can be run immediately after creation if the flag is not specified. 
STACK_SIZE_PARAM_IS_A_RESERVATION The dwStackSize parameter specified the maximum stack size instead of being ignored. 

lpThreadId 
[out] Long pointer to a 32-bit variable that receives the thread identifier. 
If this parameter is NULL, the thread identifier is not returned. 

Return Values
A handle to the new thread indicates success. NULL indicates failure. To get extended error information, call GetLastError. 

Remarks
The number of threads a process can create is limited by the available virtual memory. The number of threads that can be created depends on the default stack size. If every thread has one megabyte of stack space, you can create 32 threads maximum. If you reduce the default stack size, you can create more threads. However, your application will have better performance if you create one thread per processor and build queues of requests for which the application maintains the context information. A thread would process all requests in a queue before processing requests in the next queue. 

The new thread handle is created with THREAD_ALL_ACCESS to the new thread. The handle can be used in any function that requires a thread object handle. 

The thread execution begins at the function specified by the lpStartAddress parameter. If this function returns, the DWORD return value is used to terminate the thread in an implicit call to the ExitThread function. Use the GetExitCodeThread function to get the thread's return value. 

The CreateThread function may succeed even if lpStartAddress points to data, code, or is not accessible. If the start address is invalid when the thread runs, an exception occurs, and the thread terminates. Thread termination due to a invalid start address is handled as an error exit for the thread's process. This behavior is similar to the asynchronous nature of CreateProcess, where the process is created even if it refers to invalid or missing dynamic-link libraries (DLLs). 



The thread is created with a thread priority of THREAD_PRIORITY_NORMAL. Use the GetThreadPriority and SetThreadPriority functions to get and set the priority value of a thread. 

When a thread terminates, the thread object attains a signaled state, satisfying any threads that were waiting on the object. 

The thread object remains in the system until the thread has terminated and all handles to it have been closed through a call to CloseHandle. 

The ExitThread function, CreateThread function, and a process that is starting (as the result of a call by CreateProcess) are serialized between each other within a process. Only one of these events can happen in an address space at a time. The following list shows the restrictions during the process: 

During process startup and DLL initialization routines, new threads can be created, but they do not begin execution until DLL initialization is done for the process. 
In a process, only one thread at a time can be in a DLL initialization or detach routine. 
Requirements
OS Versions: Windows CE 1.01 and later.
Header: Winbase.h.
Link Library: Coredll.lib.


[解决办法]
这么多同志都说createthread了,呵呵

热点排行