NET 线程可传递参数
程序员文章站
2022-08-05 22:18:15
1.多线程执行方法 2.线程调用 ......
1.多线程执行方法
/// <summary> /// 随机数保存队列 /// </summary> private queue<string> _randomqueue = new queue<string>(); stringbuilder builder = new stringbuilder(); /// <summary> /// 生成随机数,保存到队列中 /// </summary> /// <param name="number"></param> private void builderrandom() { builderrandom(72, clicksum); } /// <summary> /// 生成随机数,保存到队列中 /// </summary> /// <param name="number"></param> private void builderrandom(int number, int clicksum) { builder.insert(0, $"{datetime.now.tostring("yy-mm-dd hh:mm:ss.fff")}_第【{clicksum}】次点击_生成【{number}】组数据_开始生成\r\n"); //builder.appendline($"{datetime.now.tostring("yy-mm-dd hh:mm:ss.fff")}_第【{clicksum}】次点击_生成【{number}】组数据_开始生成"); random random = new random(guid.newguid().gethashcode()); for (int i = 0; i < number; i++) { _randomqueue.enqueue($"第【{clicksum}】次点击_生成【{number}】组数据_第【{number}】组数据_{datetime.now.tostring("yy-mm-dd hh:mm:ss.fff")}_{random.next()}"); } builder.insert(0, $"{datetime.now.tostring("yy-mm-dd hh:mm:ss.fff")}_第【{clicksum}】次点击_生成【{number}】组数据_生成结束\r\n"); }
2.线程调用
/// <summary> /// thread生成随机数-无参 /// </summary> /// <param name="number"></param> /// <param name="clicksum"></param> private void threadbuilderrandom() { thread thread = new thread(builderrandom); thread.start(); } /// <summary> /// thread生成随机数-有参 /// </summary> /// <param name="number"></param> /// <param name="clicksum"></param> private void threadbuilderrandom(int number, int clicksum) { thread thread = new thread(() => { builderrandom(number, clicksum); }); thread.start(); }
下一篇: 同一张表中有父子键关联进行查询