110,538
社区成员
发帖
与我相关
我的任务
分享
t.Elapsed += (o, e) =>
{
//可能通过一些逻辑判断从静态的list里取值并且给UI的文本框赋值
var list=static.t;
textbox1.BeginInvoke(new action(()=>{
textbox1.text=list.find(d=>d.name="小明").age;
lx.add(1);//这句我认为可能导致内存增加..所以有了下面一句
if (lx.Count >= 2000)
{
lx.RemoveRange(0, lx.Count - 2000);
}
}));
}
lx = lx.RemoveRange(0, lx.Count - 2000);
public class common
{
public static List<int> a = new List<int>();
public static List<int> b = new List<int>();
public static List<int> c = new List<int>();
public static List<int> d = new List<int>();
}
public class model
{
public string a { get; set; }
public string b { get; set; }
public string c { get; set; }
public string d { get; set; }
}
UI上拖4个文本框就够了. 代码如下
public List<model> list { get; set; }
private void Form1_Load(object sender, EventArgs e)
{
list = new List<model>();
common.a = Enumerable.Range(1, 100).ToList();
common.b = Enumerable.Range(1, 100).ToList();
common.c = Enumerable.Range(1, 100).ToList();
common.d = Enumerable.Range(1, 100).ToList();
var timer = new System.Timers.Timer(666);
timer.Enabled = true;
timer.Elapsed += (a, b) =>
{
this.BeginInvoke(new Action(() =>
{
var model = new model();
model.a = common.a.OrderBy(d => Guid.NewGuid()).FirstOrDefault().ToString();
model.b = common.b.OrderBy(d => Guid.NewGuid()).FirstOrDefault().ToString();
model.c = common.c.OrderBy(d => Guid.NewGuid()).FirstOrDefault().ToString();
model.d = common.d.OrderBy(d => Guid.NewGuid()).FirstOrDefault().ToString();
textBox1.Text = model.a;
textBox2.Text = model.b;
textBox3.Text = model.c;
textBox4.Text = model.d;
list.Add(model);
if (list.Count >= 2000)
{
list.RemoveRange(0, list.Count - 2000);
}
}));
};
}