60 lines
1.3 KiB
C#
60 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace WindowsFormsAppTask
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Button1_Click(object sender, EventArgs e)
|
|
{
|
|
var t = new Task(DoIt);
|
|
t.Start();
|
|
|
|
for (int i = 0; i < 999; i++)
|
|
{
|
|
textBox1.Text += "-";
|
|
Application.DoEvents(); //update ui elements
|
|
Thread.Sleep(100);
|
|
}
|
|
}
|
|
|
|
|
|
private void DoIt()
|
|
{
|
|
//Console.WriteLine(".");
|
|
|
|
for (int i = 0; i < 999; i++)
|
|
{
|
|
if (textBox1.InvokeRequired)
|
|
{
|
|
textBox1.Invoke(new MethodInvoker(() => { textBox1.Text += "x"; }));
|
|
}
|
|
else
|
|
{
|
|
textBox1.Text += "x";
|
|
}
|
|
|
|
Random random = new Random();
|
|
Thread.Sleep(random.Next(100, 500));
|
|
}
|
|
}
|
|
|
|
private void TextBox1_TextChanged(object sender, EventArgs e)
|
|
{
|
|
}
|
|
}
|
|
} |