Книга: Microsoft Windows Embedded CE 6.0 Exam Preparation Kit

? Create a Thread

? Create a Thread

1. Using the New Project Wizard, create a new WCE Console Application named HelloWorld. Use the Typical Hello_World Application option.

2. Before the _tmain function, implement a thread function named ThreadProc:

DWORD WINAPI ThreadProc( LPVOID lpParameter) {
 RETAILMSG(1,(TEXT("Thread started")));
 // Suspend Thread execution for 3 seconds
 Sleep(3000);
 RETAILMSG(1,(TEXT("Thread Ended")));
 // Return code of the thread 0,
 // usually used to indicate no errors.
 return 0;
}

3. By using the CreateThread function, start a thread:

HANDLE hThread = CreateThread( NULL, 0, ThreadProc, NULL, 0, NULL);

4. Check the returned value of CreateThread to verify that the thread was created successfully.

5. Wait for the thread to reach the end of the thread function and exit:

WaitForSingleObject(hThread, INFINITE);

6. Build the run-time image and download it to the target device.

7. Launch Remote Kernel Tracker and analyze how threads are managed on the system.

8. Start the HelloWorld application and follow the thread execution in the Remote Kernel Tracker window, as illustrated in Figure 3–11.


Figure 3-11 Tracking thread execution in Remote Kernel Tracker tool

Оглавление книги


Генерация: 0.615. Запросов К БД/Cache: 2 / 0
поделиться
Вверх Вниз