AfxBeginThread
-
i have a function that i want a worker thread to execute it, my function is of the type bool wmi(IP) Can i use AfxBeginThread() with this or can only void functions be called? how can i pass a variable back or do i have to use a pointer? thanks
-
i have a function that i want a worker thread to execute it, my function is of the type bool wmi(IP) Can i use AfxBeginThread() with this or can only void functions be called? how can i pass a variable back or do i have to use a pointer? thanks
if u want to pass a variable back, u must use a pointer. code is in this way: ...ThreadFunction(void*pv) { SomeClass*pc=(SomeClass*)pv; pc->SomeVariableBack=...; } it may not be what u want ...
A special image tool for Windows C++ programmers, don't miss it! The world unique Software Label Maker is waiting for you and me ... A nice hyper tool for optimizing your Microsoft html-help contents.
-
i have a function that i want a worker thread to execute it, my function is of the type bool wmi(IP) Can i use AfxBeginThread() with this or can only void functions be called? how can i pass a variable back or do i have to use a pointer? thanks
viperlogic wrote:
Can i use AfxBeginThread() with this
Indirectly you can. Something like:
AfxBeginThread(ThreadProc);
...
UINT ThreadProc( LPVOID lpParam )
{
wmi();
}You'll likely need to use the second argument to
AfxBeginThread()
as a way to call or communicate with thewmi()
function.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
viperlogic wrote:
Can i use AfxBeginThread() with this
Indirectly you can. Something like:
AfxBeginThread(ThreadProc);
...
UINT ThreadProc( LPVOID lpParam )
{
wmi();
}You'll likely need to use the second argument to
AfxBeginThread()
as a way to call or communicate with thewmi()
function.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
thx for the reply how would i implement a timer, so that after say 5secs if the thread hasnt finished, kill it?
-
thx for the reply how would i implement a timer, so that after say 5secs if the thread hasnt finished, kill it?
Use
WaitForSingleObject()
for this.CWinThread *pThread = AfxBeginThread(..., CREATE_SUSPENDED);
pThread->m_bAutoDelete = FALSE;
pThread->ResumeThread();
...
switch(WaitForSingleObject(pThread->m_hThread, 5000))
{
case WAIT_TIMEOUT:
// need to kill the thread
break;case WAIT\_OBJECT\_0: // thread has terminated on its own break;
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Use
WaitForSingleObject()
for this.CWinThread *pThread = AfxBeginThread(..., CREATE_SUSPENDED);
pThread->m_bAutoDelete = FALSE;
pThread->ResumeThread();
...
switch(WaitForSingleObject(pThread->m_hThread, 5000))
{
case WAIT_TIMEOUT:
// need to kill the thread
break;case WAIT\_OBJECT\_0: // thread has terminated on its own break;
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
thx for the replys i am having trouble implementing AfxBeginThread()
void CScanDlg::OnButtonScan() { AfxBeginThread(ThreadProc); } UINT CScanDlg::ThreadProc(LPVOID pParam) { if(wmi(strIP1)) return 0; else return 1; }
what is wrong above, sorry about these questions but this is new to me -
thx for the replys i am having trouble implementing AfxBeginThread()
void CScanDlg::OnButtonScan() { AfxBeginThread(ThreadProc); } UINT CScanDlg::ThreadProc(LPVOID pParam) { if(wmi(strIP1)) return 0; else return 1; }
what is wrong above, sorry about these questions but this is new to meviperlogic wrote:
i am having trouble implementing AfxBeginThread()...
Aside from not suppling enough arguments, what troubles are you having?
viperlogic wrote:
UINT CScanDlg::ThreadProc(LPVOID pParam)
Is this a
static
member?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
viperlogic wrote:
i am having trouble implementing AfxBeginThread()...
Aside from not suppling enough arguments, what troubles are you having?
viperlogic wrote:
UINT CScanDlg::ThreadProc(LPVOID pParam)
Is this a
static
member?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
ok this is what i have.. static UINT CScanDlg::ThreadProc(LPVOID pParam); delcared in the header file
AfxBeginThread(ThreadProc,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);
UINT CScanDlg::ThreadProc(LPVOID pParam) { if(wmi(strIP1)) return 0; else return 1; }
i get the following error CScanDlg::wmi' : illegal call of non-static member function -
ok this is what i have.. static UINT CScanDlg::ThreadProc(LPVOID pParam); delcared in the header file
AfxBeginThread(ThreadProc,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);
UINT CScanDlg::ThreadProc(LPVOID pParam) { if(wmi(strIP1)) return 0; else return 1; }
i get the following error CScanDlg::wmi' : illegal call of non-static member functionTry:
AfxBeginThread(ThreadProc, this);
...
UINT CScanDlg::ThreadProc( LPVOID pParam )
{
CScanDlg *pDlg = (CScanDlg *) pParam;if (pDlg->wmi(strIP1)) return 0; else return 1;
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Try:
AfxBeginThread(ThreadProc, this);
...
UINT CScanDlg::ThreadProc( LPVOID pParam )
{
CScanDlg *pDlg = (CScanDlg *) pParam;if (pDlg->wmi(strIP1)) return 0; else return 1;
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
thx, that worked can explain why thou?