Запуск каждые n-секунд по таймеру - C#
Формулировка задачи:
Необходимо создать таймер, чтобы через каждые n секунд открывалось приложение (т.е. если всего 4 приложения задано в форме, то сначала откроется 1, через n секунд 2 и т.д.)
я так понимаю что надо прописать в таймер
а потом в
Хотя бы просто на словах. Я уже кучу примеров на форуме перерыла.
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
}private void Start_Click(object sender, EventArgs e)
{
timer1.Interval = time;
timer1.Enabled = true;
... и здесь как-то счетчик?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;
namespace program1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Text = "Lab2";
}
private void Ente_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
richTextBox1.Text = openFileDialog1.FileName;
}
private void Start_Click(object sender, EventArgs e)
{
bool hide = checkBox1.Checked;
if (hide) this.Hide();
try
{
int quantity = int.Parse(richTextBox3.Text);
for (int i = 0; i < quantity; i++)
{
ManagementClass classInstance =
new ManagementClass("root\\CIMV2",
"Win32_Process", null);
// Obtain in-parameters for the method
ManagementBaseObject inParams =
classInstance.GetMethodParameters("Create");
// Add the input parameters.
inParams["CommandLine"] = richTextBox1.Text;
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
classInstance.InvokeMethod("Create", inParams, null);
// List outParams
ID_Process.Text = Convert.ToString(outParams["ProcessId"]);
}
}
catch (Exception Er)
{ MessageBox.Show(Er.Message, "Error"); }
if (hide) this.Show();
}
private void Stop_Click(object sender, EventArgs e)
{
try
{
ManagementObject classInstance =
new ManagementObject("root\\CIMV2",
"Win32_Process.Handle='" + ID_Process.Text + "'",
null);
// Obtain in-parameters for the method
ManagementBaseObject inParams =
classInstance.GetMethodParameters("Terminate");
// Add the input parameters.
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
classInstance.InvokeMethod("Terminate", inParams, null);
// List outParams
richTextBox1.AppendText("\n Out parameters:");
richTextBox1.AppendText("\n ReturnValue: " + outParams["ReturnValue"]);
}
catch (Exception Er)
{ MessageBox.Show(Er.Message, "Error"); }
}
}
}Решение задачи: «Запуск каждые n-секунд по таймеру»
textual
Листинг программы
string[] files;//список запускаемых файлов
int n = 1;//задержка между запусками
foreach(string file in files)
{
Process.Start(file);
Thread.Sleep(TimeSpan.FromSeconds(n));
}