
Need simple example of creating a thread (during a long process)
Quote:
> My program needs to complete a long database function that takes about 10
> minutes, during which the program must not be used.
> It is a very simple situation, meaning the process cannot be cancelled and
> there is no progress bar.
> The problem is that when this step is running, my title bar displays "Not
> Responding" - and the window cannot be resized/moved etc. It stops
> responding to the mouse. It also does not redraw itself if another window is
> moved over it.
> What should I do so that my window still responds to mouse movements and
> redraws itself? I know I have to run that long step in a different thread
> but I've never written such a threaded app. Can someone post a simple
> example of how to do this?
> Thanks!
I would caution you that some database interfaces do not permit access
from
a secondary thread: see your docs. But this is how to run a bare
essentials worker thread...
// .h
UINT ThreadFunc(LPVOID pParam); // not a class member
// .cpp
// call from within CYourClass
AfxBeginThread(ThreadFunc, this);
UINT ThreadFunc(LPVOID pParam)
{
CYourClass* p = (CYourClass*)pParam;
...do things with p->data_members
return 0;
Quote:
}
--
Scott McPhillips [VC++ MVP]