Re: Thread.Abort()



Hi !

I just went to http://msdn2.microsoft.com/en-us/library/ty8d3wta.aspx to verify your statement about the deprecation of this methods, but could not verify.

Additionally, I would leave net immidiately;For example, if your mentioned "copy a file to a location", would need too much time, because the underlying system is not resposnible, I must have the option to kill that thread and re-try the whole operation at a later moment. Naturally, one has to deal with dataconsitency in this case very strong.

Just my two cents.
Best regards,
Manfred

Adityanand Pasumarthi wrote:
Hi Alan,

Here is how your class and thread method handler maylook like...

Class MyThreadWrapper
private _myThread
// (Important: Default state should be signaled, i.e. True)
private _continueEvent System.Threading.ManualResetEvent private enumerated type _state (pause, stop, start, resume)
method Pause
{ set _state = pause, _continueEvent.Reset() }
method Stop
{ set _state = stop, _continueEvent.Set() }
method Start
{ set _state = start
_myThread.Start()
}
method Resume
{ set _state = resume, _continueEvent.Set() }
procedure DoSomething()
loop
_continueEvent.Wait(-1) // Wait infinitely on the manual reset event
if (_state == stop) { break; }
Copy a file to a location
Update database record
Read the file content
Write the content to a log file
end loop

What we are doing here is that the thread loop will just wait for ManualResetEvent to be in signaled state (_continueEvent.Set()) before continuing with every iteration in the loop. The event will be in this state when the thread first starts. When we call Pause the_continueEvent will be in non-signaled state and the thread will finish the current loop iteration and then before begining the next iteration will wait for the event to be in signaled state. When we call Resume after some time the _continueEvent will be set to signaled state and the thread will start running again.

Calling Stop() when we are in running state (start or resume) will cause the loop to terminate after completing its current iteration. Calling Stop() when we are in pause state will set the _continueEvent to signaled state and immediately since the _state is stop, the loop will break and the thread will end safely.

Let me know if this helps.

.



Relevant Pages

  • Re: New to threading. Need suggestions
    ... I would use a ManualResetEvent for this. ... Then, in your worker thread, on each iteration of the loop, you call ... loop, your thread will pause. ...
    (microsoft.public.dotnet.languages.csharp)
  • Yow! LOOP macros are LOOPY!
    ... By relying entirely on procedure calls to express iteration, ... to but cleaner than C's FOR loop. ... other macros going around at the time other than MacLisp's ... (bind (vi (vector-ref v i))) ...
    (comp.lang.scheme)
  • Re: Polling, Interrupts, DMA, Synchronous, Asynchronous I/O Definitions
    ... the terminology is less useful than it might be. ... though a "message loop" could arguably be claimed to be ... considering in a particular iteration but what is true for _ALL_ ... watching the "polling" version eating up every single CPU cycle ...
    (alt.lang.asm)
  • Re: Histogram of character frequencies
    ... generated object code may simply be a loop in which elements are ... believe any C compiler anywhere would reject it. ... On the first iteration of the loop you test the end of file indicator ...
    (comp.lang.c)
  • Re: Random number help
    ... is used to generate cooccurance matrix for each iteration of for loop. ... disp('the sample co-occurance matrix is as follows');% GIVING SAME ...
    (comp.soft-sys.matlab)