1 #include<windows.h>
2 #include<iostream>
3 #include<thread>
4 HANDLE h1;
5 HANDLE h2;
6
7 void CALLBACK test(PVOID a, BOOLEAN b)
8 {
9 std::cout << "This a test function excuted by Thread:" << std::this_thread::get_id()<< std::endl;
10 //std::cout << "Here we try to delete timer in Thread:" << std::this_thread::get_id() << std::endl;
11 if (0 == DeleteTimerQueueTimer(NULL, h1, INVALID_HANDLE_VALUE))
12 {
13 std::cout << "Timer Deleted Failed in Thread:" << std::this_thread::get_id() << std::endl;
14 }
15 std::cout << "Timer Deleted Successfully in Thread:" << std::this_thread::get_id() << std::endl;
16
17 }
18 void CALLBACK test1(PVOID l, BOOLEAN t)
19 {
20 std::cout << "This a test1 function excuted by Thread:" << std::this_thread::get_id() << std::endl;
21 }
22
23 int main()
24 {
25
26 std::cout << "******This is a Test for TimeQueueTimer in Windows API******" << std::endl;
27 std::cout << "Main thread is executed by thread: " << std::this_thread::get_id() << std::endl;
28 //test(PVOID(1), TRUE);
29 try
30 {
31 CreateTimerQueueTimer(&h1, NULL, WAITORTIMERCALLBACK(test), NULL, 0, 1000, WT_EXECUTEINTIMERTHREAD);
32 //Sleep(1000);
33
34 CreateTimerQueueTimer(&h2, NULL, WAITORTIMERCALLBACK(test1), NULL, 0, 1000, WT_EXECUTEINTIMERTHREAD);
35
36
37 //CreateTimerQueueTimer(&h1, NULL, [](PVOID lpParameter, BOOLEAN TimerOrWaitFired) {
38 // test(lpParameter, TimerOrWaitFired); // Call your original test function from within the lambda
39 // }, NULL, 0, 1000, WT_EXECUTEINTIMERTHREAD);
40
41 }
42 catch (const std::exception& e)
43 {
44 std::cout << "something error with the timer: " << e.what() << std::endl;
45 }
46
47
48 if (std::cin.get())
49 {
50 if (0 == DeleteTimerQueueTimer(NULL, h2, INVALID_HANDLE_VALUE))
51 {
52 std::cout << "Timer Deleted Failed in Thread:" << std::this_thread::get_id() << std::endl;
53 }
54 std::cout << "Timer Deleted Successfully in Thread:" << std::this_thread::get_id() << std::endl;
55
56 };
57 Sleep(1000);
58
59 return 0;
60 }
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.