Действие по таймеру выполняется в отдельном или общем потоке - C#
Формулировка задачи:
Добрый день!
Если я ставлю в программу таймер и на tick вешаю функцию, то будет ли на время выполнения этой функции останавливаться другие ф-ии программы?
Решение задачи: «Действие по таймеру выполняется в отдельном или общем потоке»
textual
Листинг программы
public class Form1 : Form { private readonly Button button1; private readonly TextBox textBox1; private readonly Timer timer1; public Form1() { components = new Container(); timer1 = new Timer(components); button1 = new Button(); textBox1 = new TextBox(); SuspendLayout(); // // timer1 // timer1.Enabled = true; timer1.Tick += timer1_Tick; // // button1 // button1.Location = new Point(66, 25); button1.Name = "button1"; button1.Size = new Size(75, 23); button1.TabIndex = 0; button1.Text = "button1"; button1.UseVisualStyleBackColor = true; // // textBox1 // textBox1.Location = new Point(66, 65); textBox1.Name = "textBox1"; textBox1.Size = new Size(100, 20); textBox1.TabIndex = 1; // // Form1 // AutoScaleDimensions = new SizeF(6F, 13F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(284, 261); Controls.Add(textBox1); Controls.Add(button1); Name = "Form1"; Text = "Form1"; ResumeLayout(false); PerformLayout(); } private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; while (true) { } } /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д