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";
}
}
}

Sam HobbsRank #107 · 20.5K reputationPosted Sep 17, 2010, 5:06 PM EDT
Mahesh ChandRank #1 · 393.3K reputationPosted Sep 17, 2010, 6:51 PM EDT
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.
Dozd59 reputationPosted Sep 18, 2010, 2:20 AM EDT
Benjamin Scharbach20 reputationPosted Oct 14, 2017, 9:59 AM EDT