Where is your first code executing?
There's some very basic initialization which doesn't happen and the code therefore appears incomplete.
I've added a presumed context and initialization for you, please do that yourself in a future scenario, to save your helpers time ;)
Of cause the thread sleep and the tick number displaying should be replaced with your values. Also if you stick to the Windows forms timer you will not need the invoke bits, just in there for habit when dealing with timers and windows controls, plus you could quickly not want to use that anyway, in which case it will be required.
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 FormDriblings
{
public partial class Form1 : Form
{
private System.Windows.Forms.Timer _time = new System.Windows.Forms.Timer();
public delegate void UpdateInstantiator();
public Form1()
{
InitializeComponent();
GroupBox grp = new GroupBox();
grp.Name = "dynbox";
int x, y, lblx, lbly;
x = y = 0;
for (int i = 1; i < 6; i++)
{
grp = new GroupBox();
grp.Name = "GRP" + i;
grp.Location = new Point(x, y);
grp.Size = new Size(260, 272);
var lbl = new Label();
x += 270;
lblx = 10;
lbly = 210;
var lblname = "lblCharName";
lbl = Labelcreate(lbl, lblname, i, lblx, lbly);
grp.Controls.Add(lbl);
Controls.Add(grp);
}
_time.Interval = 1000;
_time.Tick += _time_Tick;
_time.Start();
}
private bool _timeTicking;
void _time_Tick(object sender, EventArgs e)
{
if (_timeTicking) return;
_timeTicking = true;
try
{
UpdateGroups();
}
finally
{
_timeTicking = false;
}
}
private void UpdateGroups()
{
if (InvokeRequired)
{
Invoke(new UpdateInstantiator(UpdateGroups));
}
else
{
for (int i = 1; i < 6; i++)
{
var lbl = (Label) Controls.Find("lblCharName" + i, true).First();
string number = DateTime.Now.Ticks.ToString();
number = number.Substring(number.Length - 3);
lbl.Text = string.Format("{0}.00", number);
lbl.Refresh();
Thread.Sleep(120);
}
}
}
private Label Labelcreate(Label lbl, string lblname, int i, int x, int y)
{
lbl.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
lbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
lbl.Location = new System.Drawing.Point(x, y);
lbl.Name = lblname + i;
lbl.Size = new System.Drawing.Size(116, 40);
lbl.TabIndex = 1;
lbl.Text = "0.00";
lbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
return lbl;
}
}
}