Need simple example of creating a thread (during a long process) 
Author Message
 Need simple example of creating a thread (during a long process)

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!



Wed, 02 Mar 2005 00:57:47 GMT  
 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]


Wed, 02 Mar 2005 02:52:27 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Simple problem across processes - need simplest answer

2. Crash during Thread process in WinNT4

3. Example of a simple worker thread?

4. Simple DataGrid example needed

5. need example of simple TSR

6. need simple example

7. Need Simple example of Explicitly linked DLL

8. I need a Simple Frame Control Example

9. Process Windows Messages during lengthy process

10. How to use CreateProcess() ? [need simple explanation/example]

11. Comm Port: Simple SDI Example Needed

12. Threads created inside a process

 

 
Powered by phpBB® Forum Software