41 lines
955 B
C++
Executable File
41 lines
955 B
C++
Executable File
#pragma once
|
|
#include "Windows.h"
|
|
#include <functional>
|
|
|
|
namespace CTL {
|
|
class Thread
|
|
{
|
|
public:
|
|
Thread();
|
|
template<typename FUN, typename... ARGS>
|
|
Thread(FUN&& fun, ARGS&& ...Args);
|
|
~Thread();
|
|
DWORD GetThreadId() const;
|
|
template<typename FUN, typename... ARGS>
|
|
bool SetThread(FUN&& fun, ARGS&& ...Args);
|
|
void Wait();
|
|
void Start();
|
|
void StartDetch();
|
|
static void SleepMS(int ms);
|
|
private:
|
|
static DWORD WINAPI MyThreadFunction(LPVOID lpParam);
|
|
int Mode = 0;
|
|
bool IsStop = false;
|
|
public:
|
|
private:
|
|
HANDLE hThread;
|
|
DWORD dwThreadId;
|
|
std::function<void()> task_Fun;
|
|
};
|
|
template<typename FUN, typename ...ARGS>
|
|
inline Thread::Thread(FUN&& fun, ARGS && ...Args)
|
|
{
|
|
SetThread(fun, Args...);
|
|
}
|
|
template<typename FUN, typename ...ARGS>
|
|
inline bool Thread::SetThread(FUN&& fun, ARGS && ...Args)
|
|
{
|
|
task_Fun = std::bind(std::forward<FUN>(fun), std::forward<ARGS>(Args)...);
|
|
return task_Fun ? true : false;
|
|
}
|
|
} |