Interrupts?
-
Hi everybody, I'm using a function taken from a DLL. It can be a lengthy wait for it to finish so I want to create a stop button to stop the function if the function begins to take too long. As the function is in the dll, I don't know how to stop the function. Could anyone help me in teaching me how to do this? Thanks! wilche :)
-
Hi everybody, I'm using a function taken from a DLL. It can be a lengthy wait for it to finish so I want to create a stop button to stop the function if the function begins to take too long. As the function is in the dll, I don't know how to stop the function. Could anyone help me in teaching me how to do this? Thanks! wilche :)
You can load and excecute that function in a seperate thread and when u want to stop just terminate that thread... i think that work perfect..!! R_Renjith The True CP ian
-
You can load and excecute that function in a seperate thread and when u want to stop just terminate that thread... i think that work perfect..!! R_Renjith The True CP ian
Thanks for your reply. Not disputing what you said but I have some questions.... If I used worker thread, for example the following code: //ThreadProc is the procedure used by worker thread int ThreadProc() { // event declarations and def event[0] = ::CreateEvent(NULL, TRUE, FALSE, NULL) // Stop/abort event[1] = ::CreateEvent(NULL, TRUE, FALSE, NULL) // Run DWORD status; while(TRUE) { status = WaitForMultipleObjects(2, event, FALSE, infinite); switch(status) { case WAIT_OBJECT_0: // Abort CloseHandle(ThreadId); return result; case WAIT_OBJECT_0+1: result = RunFunction(); break; } } return result; } In this case, wouldn't it still wait for RunFunction to finish before processing the Abort Event? If I create an UI thread using message queue, I do something similar using GetMessage say. int ThreadProc() { DWORD status; while(TRUE) { status = GetMessage(&msg, NULL, 0, 0); // Check that the message is valid...code ignored here. Assume it's ok switch(msg.message) { case abort: // Abort CloseHandle(ThreadId); return result; case run: result = RunFunction(); break; } } return result; } Would I still have the same problem? In this case, RunFunction will have to be completed before the next message will be processed. Kind regards, wilche