I have the following code fragment from a project I'm working on:
public void Start()
{
Thread t = new Thread(NotifyIfNecessary);
Threads.Add(t);
t.Start();
t.Abort());
}
What I want is that thread 't' should execute the method NotifyIfNecessary and abort only after the method has completed execution. In my current code, t.Abort() gets called prematurely.
This is being caused because you're creating a new thread and starting it, then immediately killing it from the thread that you just created it in by calling the Thread.Abort()
method. You don't need to do this; your thread will finish when NotifyIfNecessary
has completed execution. Just remove the line t.Abort();
and your code should work properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With