I have button call this code
private void but_Click(object sender, EventArgs e)
{
Thread My_Thread = new Thread(() => Send_File());
My_Thread.IsBackground = true;
My_Thread.Start();
}
I want a way to kill
My_Thread
from the function
Send_File()
please help me how to fix it ??? 🙁
Just declare your thread globally like any other variable (eg. int or string) you are using in different functions:
and then use it:
and kill it:
If you are talking about Send_File running in the thread, just exit it for example using
break, stop all loops to complete it.EDIT:
As Austin Salonen has stated in his comment this would overwrite the thread reference. My suggestion would be using a thread list.
and use it:
You just need to remember the index of the list to create a reference to the thread again.
To abort a thread just use its index:
or just let the thread return.