I have a method which does some work and calls a method after it's done. In this newly called method, I stopped the thread.
however if I stop the thread, all the following line will not be read. Is there any proper way to stop the thread and start it back?
Here is my code snippet:
public partial class Form1 : Form
{
string strProvider;
MySqlConnection sqlConn;
MySqlCommand command;
MySqlDataReader Reader;
Thread workerThread;
public Form1()
{
InitializeComponent();
initializedb();
workerThread = new Thread(shows);
workerThread.Start();
workerThread.IsBackground = true;
public void shows()
{
string k;
command.CommandText = "SELECT * FROM imageframe1";
sqlConn.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
k = (string)(Reader.GetValue(1));
pictureBox1.Image = Image.FromFile(k);
Thread.Sleep(3000);
}
sqlConn.Close();
stopthread();
}
public void stopthread()
{
workerThread.Abort();
//*************everything after this line wont run********
MessageBox.Show("end");
//Thread.Sleep(3000);
//workerThread.Start();
}
what im doing here is that im doing a slideshow of pictures.so i want to stop the thread and start it back,check db for new images and re run the whole thing instead of looping inside of it will use a lot of memory resources.but problem is when i stop it, i cant run anything after that.
could anyone please shed some light for a beginner here??with examples would be really good for me to understand.