By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

how do i abort a process of any thread that is taking time more than 8 seconds.

P: 18
hi all,

i am using this code to initialize and assign it to a process, i am calling a thread on every 10 Seconds to fire vbscript file, this activity is performed on "timer1_Tick( )" event and give me required information. some times i face problem that the second thread associated with "Dummy.vbs" script file, do not reach at specified remote machine, and give error message after 45 seconds to 1 minute,

i want that to terminate its process and thread after waiting 8 seconds, if that remote system is not responding.

how could i terminate thread that has not commited his process with in 8 seconds by giving any proper message

so here is given a code that i am using, some body please inform me about it.

Expand|Select|Wrap|Line Numbers
  1. public partial class MainForm : Form  
  2.    {   
  3.       int count = 0;  
  4.        string scrpt_path, scrpt_file;
  5.        DateTime strt_time, end_time;     
  6.     TimeSpan duration;    
  7.  
  8.  Thread t1 = new Thread(new parameterizedThreadStart(RunProcess));
  9.  Thread t2 = new Thread(new ParameterizedThreadStart(RunProcess));
  10.  
  11.  System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
  12.  
  13.    private void timer1_Tick(object sender, EventArgs e)
  14.         {
  15.             if (!t1.IsAlive)
  16.             {
  17.                 t1 = new Thread(new ParameterizedThreadStart(RunProcess));
  18.                 t1.Start("C:\\New folder\\abc.vbs");
  19.  
  20.             }
  21.            if (!t2.IsAlive)
  22.             {
  23.                 t2 = new Thread(new ParameterizedThreadStart(RunProcess));
  24.                 t2.Start("C:\\New folder\\Dummy.vbs");
  25.             }
  26.  
  27.         }
  28.  
  29.         static void RunProcess(object file)
  30.         {
  31.  
  32.            string VbFile = (string)file;
  33.             Process p = new Process();
  34.             p.StartInfo.FileName = VbFile;
  35.             p.Start();
  36.  
  37.         }
  38.  
  39.     }
  40.  
Nov 5 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.