Call a Function using Thread in C#

Here I will explain how to call function using thread. First of all create a function and create one thread in it. then after give a function name to thread for call it.

Finally, call the Thread. Start method to run test() function and test() function call CheckThread() function.

every 20 second thread will automatically call CheckThread() function.

  1. private void FrmEmailer_Load(object sender, EventArgs e)  
  2. {  
  3.     StartUtility();  
  4. }  
  5. private void StartUtility()  
  6. {  
  7.     Thread thread = new Thread(new ThreadStart(test));  
  8.     thread.Start();  
  9. }  
  10. public void test()  
  11. {  
  12.     while (true)  
  13.     {  
  14.         Thread.Sleep(20000);  
  15.         CheckThread();  
  16.     }  
  17. }  
  18. public void CheckThread()  
  19. {  
  20. }