当前位置: 代码迷 >> Windows Mobile >> 急待,Mobile下面要开一个线程,有API吗
  详细解决方案

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

热度:211   发布时间:2016-04-25 07:53:49.0
急急急急急!在线等待,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). 
  相关解决方案