Hi, I study threads (and timers) and I have question about UI updating. So I want to set label text property after some work method called in timer tick event. After starting Timer will be execute something in method call newtext. My idea is to pass that value in user interface exactly in label1.Text. I read a lot of articles but not success, so decide to try very simple situation for learning purpose.
Here is code in user interface:
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;
namespace UI_update
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Class1 c1 = new Class1();
c1.startT();
}
--------------------------------------------------
Here is code in class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
namespace UI_update
{
class Class1
{
System.Windows.Forms.Timer T = new System.Windows.Forms.Timer();
public string word;
public void startT()
{
T.Start();
T.Tick +=new EventHandler(T_Tick);
}
public void T_Tick(object sender, EventArgs e)
{
this.newtext();
}
public void newtext()
{
word = "Something";
}
}
}
Benjamin ScharbachPosted Oct 14, 2017, 1:59 PM
DozdPosted Sep 18, 2010, 6:20 AM
Mahesh ChandPosted Sep 17, 2010, 10:51 PM
Visit this article Timer in C# and look at part 2, Timer Control in Visual Studio 2010 that shows how to update a ListBox control on a timer event.
Sam HobbsPosted Sep 17, 2010, 9:06 PM