![]()
#include <ppltasks.h>
#include <string>
#include <windows.h>
using namespace concurrency;
using namespace std;
task<wstring> Time(DWORD tim)
{
wchar_t str[40];
int ss,ms;
ms = tim;
ss = ms / 1000;
ms = ms % 1000;
ss = ss % 60;
swprintf(str, 40, L"%d:%d", ss, ms);
auto s = make_shared<wstring>(str);
return create_task([s]
{
wstring str;
str = L"Time= " + *s + L"\n";
return str;
});
}
int wmain()
{
wstring str;
auto t = Time(GetTickCount());
str = L"Start Time: " + t.get() + L"\n";
OutputDebugString(str.data());
Sleep((rand() % 100)+500);
t = Time(GetTickCount());
str = L"End Time: " + t.get() + L"\n";
OutputDebugString(str.data());
}
|
ms = tim;
ss = ms / 1000;
ms = ms % 1000;
ss = ss % 60;
|
Start Time: Time= 35:968 End Time: Time= 36:500 |
![]()
#include <ppltasks.h>
#include <string>
#include <windows.h>
using namespace concurrency;
using namespace std;
task<int> Time(int rnd, wstring id)
{
return create_task([rnd, id]
{
DWORD ms;
wchar_t str[40];
for (int i = 0; i < 3; i++)
{
ms = GetTickCount();
swprintf(str, 40, L"%s : Time %d ミリ秒\n", id.data(), ms);
OutputDebugString(str);
Sleep(rand() % rnd);
}
return 0;
});
}
int wmain()
{
auto t = Time(200, L"A");
wchar_t str[40];
auto t2 = Time(50, L"B");
swprintf(str, 40, L"終了コード: %d %d\n\n", t.get(), t2.get());
OutputDebugString(str);
}
|
A : Time 24580625 ミリ秒 B : Time 24580625 ミリ秒 A : Time 24580687 ミリ秒 B : Time 24580687 ミリ秒 B : Time 24580718 ミリ秒 A : Time 24580750 ミリ秒 終了コード: 0 0 |
![]()
#include <ppltasks.h>
#include <string>
#include <windows.h>
using namespace concurrency;
using namespace std;
task<void> Time(int rnd, wstring id)
{
return create_task([rnd, id]
{
DWORD ms;
wchar_t str[40];
for (int i = 0; i < 3; i++)
{
ms = GetTickCount();
swprintf(str, 40, L"%s : Time %d ミリ秒\n", id.data(), ms);
OutputDebugString(str);
Sleep(rand() % rnd);
}
});
}
int wmain()
{
auto t = Time(200, L"A");
auto t2 = Time(50, L"B");
(t && t2).wait();
OutputDebugString(L"END Task\n");
}
|
A : Time 7925515 ミリ秒 B : Time 7925515 ミリ秒 B : Time 7925546 ミリ秒 A : Time 7925546 ミリ秒 B : Time 7925578 ミリ秒 A : Time 7925625 ミリ秒 END Task |
![]()
[Next Chapter ↓] Win10 Task
[Previous Chapter ↑] Task の関数値