Запуск каждые n-секунд по таймеру - C#

Узнай цену своей работы

Формулировка задачи:

Необходимо создать таймер, чтобы через каждые n секунд открывалось приложение (т.е. если всего 4 приложения задано в форме, то сначала откроется 1, через n секунд 2 и т.д.) я так понимаю что надо прописать в таймер
Листинг программы
  1. private void timer1_Tick(object sender, EventArgs e)
  2. {
  3. timer1.Enabled = false;
  4. }
а потом в
Листинг программы
  1. private void Start_Click(object sender, EventArgs e)
  2. {
  3. timer1.Interval = time;
  4. timer1.Enabled = true;
  5. ... и здесь как-то счетчик?
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Management;
  10. namespace program1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. this.Text = "Lab2";
  18. }
  19. private void Ente_Click(object sender, EventArgs e)
  20. {
  21. if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
  22. return;
  23. richTextBox1.Text = openFileDialog1.FileName;
  24. }
  25. private void Start_Click(object sender, EventArgs e)
  26. {
  27. bool hide = checkBox1.Checked;
  28. if (hide) this.Hide();
  29. try
  30. {
  31. int quantity = int.Parse(richTextBox3.Text);
  32. for (int i = 0; i < quantity; i++)
  33. {
  34. ManagementClass classInstance =
  35. new ManagementClass("root\\CIMV2",
  36. "Win32_Process", null);
  37. // Obtain in-parameters for the method
  38. ManagementBaseObject inParams =
  39. classInstance.GetMethodParameters("Create");
  40. // Add the input parameters.
  41. inParams["CommandLine"] = richTextBox1.Text;
  42. // Execute the method and obtain the return values.
  43. ManagementBaseObject outParams =
  44. classInstance.InvokeMethod("Create", inParams, null);
  45. // List outParams
  46. ID_Process.Text = Convert.ToString(outParams["ProcessId"]);
  47. }
  48.  
  49. }
  50. catch (Exception Er)
  51. { MessageBox.Show(Er.Message, "Error"); }
  52. if (hide) this.Show();
  53. }
  54. private void Stop_Click(object sender, EventArgs e)
  55. {
  56. try
  57. {
  58. ManagementObject classInstance =
  59. new ManagementObject("root\\CIMV2",
  60. "Win32_Process.Handle='" + ID_Process.Text + "'",
  61. null);
  62. // Obtain in-parameters for the method
  63. ManagementBaseObject inParams =
  64. classInstance.GetMethodParameters("Terminate");
  65. // Add the input parameters.
  66. // Execute the method and obtain the return values.
  67. ManagementBaseObject outParams =
  68. classInstance.InvokeMethod("Terminate", inParams, null);
  69. // List outParams
  70. richTextBox1.AppendText("\n Out parameters:");
  71. richTextBox1.AppendText("\n ReturnValue: " + outParams["ReturnValue"]);
  72. }
  73. catch (Exception Er)
  74. { MessageBox.Show(Er.Message, "Error"); }
  75. }
  76. }
  77. }
Хотя бы просто на словах. Я уже кучу примеров на форуме перерыла.

Решение задачи: «Запуск каждые n-секунд по таймеру»

textual
Листинг программы
  1.             string[] files;//список запускаемых файлов
  2.             int n = 1;//задержка между запусками
  3.             foreach(string file in files)
  4.             {
  5.                 Process.Start(file);
  6.                 Thread.Sleep(TimeSpan.FromSeconds(n));
  7.             }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 4.125 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы