2009年1月14日 星期三

C# 順序載入檔案開啟

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;


namespace _20090105_開機順序載入程式
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

//Delay 的用法,比Timer 方便,直接就可以停止,待時間結束 往下一行
// System.Threading.Thread.Sleep(3000);

}

private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
textBox1.Text = openFileDialog1.FileName;


}


private void button2_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
textBox2.Text = openFileDialog1.FileName;
}

private void button3_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
textBox3.Text = openFileDialog1.FileName;
}

private void button4_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
textBox4.Text = openFileDialog1.FileName;
}

private void button5_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
textBox5.Text = openFileDialog1.FileName;
}

private void button6_Click(object sender, EventArgs e)
{
button1.Dispose();
button2.Dispose();
button3.Dispose();
button4.Dispose();
button5.Dispose();
//設置 Timer 的相關資料
System.Timers.Timer tmr = new System.Timers.Timer(10000); //設置間隔時間為10000毫秒
tmr.Elapsed += new System.Timers.ElapsedEventHandler(ok_next); //到達時間的時候執行事件
tmr.AutoReset = false; //設置是執行一次(false)還是一直執行(true)
tmr.Enabled = true; //是否執行System.Timers.Timer.Elapsed事件

//無秒數 Run P1
System.Diagnostics.Process p1 = new System.Diagnostics.Process();
p1.StartInfo.FileName = textBox1.Text.ToString();
p1.StartInfo.UseShellExecute = true; //非執行檔也可以使用,若false則指定 執行檔才能執行
if (p1.StartInfo.FileName != "")
{
p1.Start();
}

}

public void ok_next(object source, System.Timers.ElapsedEventArgs e)
{
//Run P2
System.Diagnostics.Process p2 = new System.Diagnostics.Process();
p2.StartInfo.FileName = textBox2.Text.ToString();
p2.StartInfo.UseShellExecute = true; //非執行檔也可以使用,若false則指定 執行檔才能執行
if (p2.StartInfo.FileName != "")
{
p2.Start();
}

System.Timers.Timer tmr1 = new System.Timers.Timer(10000); //設置間隔時間為10000毫秒
tmr1.Elapsed += new System.Timers.ElapsedEventHandler(ok_next1); //到達時間的時候執行事件
tmr1.AutoReset = false; //設置是執行一次(false)還是一直執行(true)
tmr1.Enabled = true; //是否執行System.Timers.Timer.Elapsed事件
}

public void ok_next1(object source, System.Timers.ElapsedEventArgs e)
{
//Run P3
System.Diagnostics.Process p3 = new System.Diagnostics.Process();
p3.StartInfo.FileName = textBox3.Text.ToString();
p3.StartInfo.UseShellExecute = true; //非執行檔也可以使用,若false則指定 執行檔才能執行
if (p3.StartInfo.FileName != "")
{
p3.Start();

}

System.Timers.Timer tmr2 = new System.Timers.Timer(10000); //設置間隔時間為10000毫秒
tmr2.Elapsed += new System.Timers.ElapsedEventHandler(ok_next2); //到達時間的時候執行事件
tmr2.AutoReset = false; //設置是執行一次(false)還是一直執行(true)
tmr2.Enabled = true; //是否執行System.Timers.Timer.Elapsed事件

}

public void ok_next2(object source, System.Timers.ElapsedEventArgs e)
{
//Run P4
System.Diagnostics.Process p4 = new System.Diagnostics.Process();
p4.StartInfo.FileName = textBox4.Text.ToString();
p4.StartInfo.UseShellExecute = true; //非執行檔也可以使用,若false則指定 執行檔才能執行
if (p4.StartInfo.FileName != "")
{
p4.Start();
}

System.Timers.Timer tmr3 = new System.Timers.Timer(10000); //設置間隔時間為10000毫秒
tmr3.Elapsed += new System.Timers.ElapsedEventHandler(ok_next3); //到達時間的時候執行事件
tmr3.AutoReset = false; //設置是執行一次(false)還是一直執行(true)
tmr3.Enabled = true; //是否執行System.Timers.Timer.Elapsed事件

}

public void ok_next3(object source, System.Timers.ElapsedEventArgs e)
{

//Run P5
System.Diagnostics.Process p5 = new System.Diagnostics.Process();
p5.StartInfo.FileName = textBox5.Text.ToString();
p5.StartInfo.UseShellExecute = true; //非執行檔也可以使用,若false則指定 執行檔才能執行
if (p5.StartInfo.FileName != "")
{
p5.Start();
}

//MessageBox.Show("全數執行完畢", "AUTO", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

}
}

1 則留言: