how to kill a thread ( C# )

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manontheedge
    New Member
    • Oct 2006
    • 175

    how to kill a thread ( C# )

    I'm using C# in Visual Studio 2008, and I've run in to a problem that I can't figure out. I've created a thread using ...

    Code:
    Thread myThread = new Thread( new ThreadStart(ThreadFunction) );
    myThread.Start();
    ... this calls my function that I want spawned on a new thread.

    Anyway, the problem is that the code I have running in this new thread plays an audio file all the way through, to completion. What I want to do is to be able to kill the thread at any moment. So, since this thing plays once the thread is spawned, it can't be stopped by some condition variable, the thread needs to be killed. This is the first time I've gotten into threads in C# and can not find a way to do this. I've read numerous times that .Abort() doesn't really work, so, can anyone give me any suggestions on what I can do to kill a spawned thread?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Calling Thread.Abort just throws the ThreadAbortingE xception on the thread. So if your thread is ignoring Exceptions then it won't stop the thread.
    I don't know what code you are using to play the audio, but the windows API I know of also has "stop playing" call.

    Comment

    Working...