Click here to Skip to main content
15,919,341 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: AfxBeginThread Pin
BlackDice23-Nov-04 2:39
BlackDice23-Nov-04 2:39 
GeneralWM_SHUTDOWN notification Win32 dll Pin
AssemblySoft22-Nov-04 23:58
AssemblySoft22-Nov-04 23:58 
GeneralRe: WM_SHUTDOWN notification Win32 dll Pin
geo_m23-Nov-04 1:37
geo_m23-Nov-04 1:37 
GeneralRe: WM_SHUTDOWN notification Win32 dll Pin
AssemblySoft23-Nov-04 10:43
AssemblySoft23-Nov-04 10:43 
GeneralRe: WM_SHUTDOWN notification Win32 dll Pin
BaldwinMartin23-Nov-04 10:21
BaldwinMartin23-Nov-04 10:21 
GeneralRe: WM_SHUTDOWN notification Win32 dll Pin
AssemblySoft23-Nov-04 10:40
AssemblySoft23-Nov-04 10:40 
GeneralRe: WM_SHUTDOWN notification Win32 dll Pin
BaldwinMartin23-Nov-04 10:46
BaldwinMartin23-Nov-04 10:46 
GeneralThread termination problem. Pin
ledallam22-Nov-04 21:38
ledallam22-Nov-04 21:38 
Hi
I started a thread to check for a file change using the below code

CWinThread* m_UpdateMonitorThread = AfxBeginThread(CheckFileUpdates,(LPVOID)this)

UINT CheckFileUpdates(LPVOID lp)
{
while( ReadDirectoryChangesW(
hDir, // handle to directory
&Buffer, // read results buffer
sizeof(Buffer), // length of buffer
TRUE, // monitoring option
FILE_NOTIFY_CHANGE_SIZE, // filter conditions
&BytesReturned, // bytes returned
NULL, // overlapped buffer
NULL// completion routine
))
{
//do the work

}
}

Now on I have abutton on my UI. Onclick of the button I want to stop the above thread.

I I tried to use
if(m_UpdateMonitorThread)
{
DWORD dwRetCode;
while (!GetExitCodeThread(m_UpdateMonitorThread->m_hThread, &dwRetCode));
TerminateThread(m_UpdateMonitorThread->m_hThread,dwRetCode);
m_UpdateMonitorThread = NULL;
}
and

if(m_UpdateMonitorThread)
{
m_UpdateMonitorThread->SuspendThread();
m_UpdateMonitorThread->Delete();
m_UpdateMonitorThread = NULL;

}

I am getting memory leaks in both the above cases. I tried to post a Stop Event, but where do I wait for this event inside the thread code as execution will not go inside the while loop code because of ReadDirectoryChangesW.

Can anyone please please suggest a way out to this problem.
Thanks in anticipation of information.

Madhavi

GeneralRe: Thread termination problem. Pin
Joaquín M López Muñoz22-Nov-04 22:35
Joaquín M López Muñoz22-Nov-04 22:35 
GeneralRe: Thread termination problem. Pin
ledallam22-Nov-04 22:47
ledallam22-Nov-04 22:47 
QuestionReBar - how to set button state on it? Pin
Darked developer22-Nov-04 20:57
Darked developer22-Nov-04 20:57 
AnswerRe: ReBar - how to set button state on it? Pin
Darked developer22-Nov-04 21:02
Darked developer22-Nov-04 21:02 
GeneralRe: ReBar - how to set button state on it? Pin
pc_dev22-Nov-04 21:13
pc_dev22-Nov-04 21:13 
Generalmodeless dialog Pin
pc_dev22-Nov-04 20:04
pc_dev22-Nov-04 20:04 
GeneralRe: modeless dialog Pin
BaldwinMartin23-Nov-04 10:22
BaldwinMartin23-Nov-04 10:22 
GeneralRe: modeless dialog Pin
pc_dev23-Nov-04 18:21
pc_dev23-Nov-04 18:21 
GeneralTimers and Threads Pin
asv22-Nov-04 19:31
asv22-Nov-04 19:31 
GeneralRe: Timers and Threads Pin
shiraztk22-Nov-04 20:58
shiraztk22-Nov-04 20:58 
GeneralRe: Timers and Threads Pin
David Crow23-Nov-04 3:09
David Crow23-Nov-04 3:09 
GeneralCFileDialog i want select only directories Pin
tiziacaia22-Nov-04 19:29
tiziacaia22-Nov-04 19:29 
GeneralRe: CFileDialog i want select only directories Pin
Michael Dunn22-Nov-04 19:43
sitebuilderMichael Dunn22-Nov-04 19:43 
GeneralRe: CFileDialog i want select only directories Pin
BlackDice23-Nov-04 2:44
BlackDice23-Nov-04 2:44 
GeneralAdding unicode support Pin
Shiva Prasad22-Nov-04 18:34
Shiva Prasad22-Nov-04 18:34 
Generalmfc mysteries Pin
the_augy22-Nov-04 16:47
the_augy22-Nov-04 16:47 
GeneralRe: mfc mysteries Pin
shiraztk22-Nov-04 18:01
shiraztk22-Nov-04 18:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.