Skip to content

Instantly share code, notes, and snippets.

@nibasya
Created May 4, 2020 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibasya/6e0fe66775aa4b47a26ad0174ed97e0f to your computer and use it in GitHub Desktop.
Save nibasya/6e0fe66775aa4b47a26ad0174ed97e0f to your computer and use it in GitHub Desktop.
Example of creating worker thread
bool CProgressDlg::AddThread()
{
// Snip
CConvert* pConv = new CConvert();
CWinThread* pThread;
pThread = AfxBeginThread(CConvert::MainThread, pConv); // 重い処理をワーカースレッドで処理
// Snip
}
UINT __cdecl CConvert::MainThread(LPVOID pData)
{
UINT ret;
ret = static_cast<CConvert*>(pData)->Main(); // メンバ変数や関数の扱いを楽にするため、実装本体はMain()に記述
delete static_cast<CConvert*>(pData);
return ret;
};
UINT CConvert::Main()
{
// 重い処理
}
class CProgressDlg : public CDialogEx
{
// snip
bool AddThread();
// snip
}
class CConvert
{
public:
static UINT __cdecl MainThread(LPVOID pData);
private:
UINT Main();
// snip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment