mfc >> Suspend/Resume thread

by cmF5a29z » Mon, 31 Jan 2005 21:53:03 GMT

Hello all,
I would like to develop an ActiveX control to be used for zipping or
unzipping files.
I would also like this control to accomplish this by using a thread,
so that if there are large files to zip or unzip, it won't tie up the main
app. And,
I would also like to accomplish this without having to use any WM_MESSAGES;
so that any app using the control could
simply->GetCtrl->InitCtrl->PopulateParams->Go; without having to know or
declare/define messages. In other words, any new application should be able
to call this control dynamically if necessary.
In the control I was thinking about creating a thread in the
'SuspendedState' and then after populating the thread's necessary parameters,
do a 'ResumeThread'; however, from what I can gather, when the thread is
resumed it goes to a 'Run' function which I can override, but but when
'Run()' finishes, so does the thread?
I would like to be able for the thread to 'Suspend' after doing a file and
wait to be told to either process another file(without having to
re-create,repopulate all params,etc.), but instead just 'Resume' and process
the next file, or if necessary
do a proper ending?
Not sure if there is a way to do this by just using 'SuspendThread()' &
'ResumeThread()'(since the thread ends at the end of the 'Run' function); or
will I have to somehow use WM_MESSAGES to do what I want?

Any suggestions, ideas, examples appreciated....


TIA,

Ray K.


mfc >> Suspend/Resume thread

by Frank Hickman [MVP] » Mon, 31 Jan 2005 22:39:59 GMT






You could create a thread that "listens" for requests and then creates
another thread to actually process the request. This approach would need
some sort of IPC though. But since your creating a control, you could
simply use events/properties and/or methods to create the worker thread.

--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.






mfc >> Suspend/Resume thread

by Scott McPhillips [MVP] » Tue, 01 Feb 2005 07:35:41 GMT




This would be a simple worker thread (which does not use the Run()
loop). It can consist of one function (the thread function), containing
a while loop, which in turn contains a call to WaitForMultipleObjects.
Instead of Suspend and Resume use SetEvent. WaitForMultipleObjects will
sense the events. Use one event for "do task" and another for "exit".

The host application will probably want to know when a task is
completed. For this, you probably want a WM_MESSAGE posted back to the
host application. (Otherwise it would have to poll.)

--
Scott McPhillips [VC++ MVP]



Similar Threads

1. Pausing and resuming a thread without Suspend() and Resume()

How do you pause and resume some work without using Thread.Suspend and
Thread.Resume since they are deprecated in .NET 2.0?

2. System.Threading.Thread.Suspend/Resume and StackTrace - CSharp/C#

3. Thread.Suspend and Thread.Resume in Framework 2.0

Hello,

I want to understand whats the best way to write code to replace 
Thread.Suspend, Thread.Resume and Thread.Abort.

I have lots of code calling these existing methods and want to minimize the 
risk of changing the code everywhere so here is what I think I could do, 
which is to create my own ThreadWrapper class which inherits from Thread and 
which has these three methods already defined but does it a different way 
and then my original code can work as normal by just referencing my 
ThreadWrapper class.

Example

public class ThreadWrapper : Thread
{
     public void Abort()
    {
       // What do i do here
     }
     public void Suspend()
    {
       // What do i do here
     }
     public void Resume()
    {
       // What do i do here
     }
}

My App
public class Test
{
    static void Main(string[] args)
   {
        ThreadWrapper tw = new ThreadWrapper();
        ...
       tw.Suspend();
       tw.Resume();
       tw.Abort();
   }
}


Thanks, 


4. Suggestion about Thread.Suspend() and Thread.Resume() - CSharp/C#

5. Suspend / resume a thread given only the thread id

Hello out there,
I have the following requirement: In a third party package threads are
created like this:

    tHandle = (HANDLE) _beginthreadex(NULL, (unsigned) stackSize,
		proc, clientData, 0, (unsigned *)idPtr);  
    /*
     * The only purpose of this is to decrement the reference count so

     * the OS resources will be reaquired when the thread closes.
     */
    CloseHandle(tHandle); 

Within this package only *idPtr is used. to identify a thread.

Now I need to suspend / resume these threads, which requires the
handle - which is gone due to the call to CloseHandl.
Is there any way to suspend / resume a thread given just its 'thread
id' ?
Any help will be greatly appreciated.
Best regards
Helmut Giese

6. Replacements for thread1.Resume() and thread1.Suspend() - CSharp/C#

7. How to suspend and resume in playing a WAV file

I am using winmm.dll and I found that I can't just suspend it and
resume it?

What should I do? Any better idea?

Should I use thread? and thread.suspend will work?

Thanks

8. Automatic OS suspend-resume loop - CSharp/C#