I want to access the thread from other function in the same class.
For example
private void timer1_Tick(object sender, EventArgs e)
{
Thread thread1 = new Thread(new ThreadStart(Send1));
thread1.Start();
}
private void stop_btn_Click(object sender, EventArgs e)
{
thread1.Stop();
}
I wan to access thead1 from stop_btn_Click event. Both functions are in the same class Form1.
Declare
private Thread thread1;on the class level rather than methodBy looking at the method name
timer1_Tick()I can assume that you are simulating a timer behaviour. Take a look at the System.Timers.Timer and System.Threading.Timer classes perhaps you’ll find them more useful for your case.