Created
May 4, 2020 16:27
-
-
Save nibasya/6e0fe66775aa4b47a26ad0174ed97e0f to your computer and use it in GitHub Desktop.
Example of creating worker thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
{ | |
// 重い処理 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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