zoukankan      html  css  js  c++  java
  • NET 线程可传递参数

    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}】组数据_开始生成
    ");
                //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}】组数据_生成结束
    ");
            }

    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();
            }
  • 相关阅读:
    Python对象
    python 迭代器和生成器
    python中logging日志模块详解
    学习中遇到的一些问题(杂谈)
    如何在github上搜索项目
    python闭包与装饰器
    python面试题
    selenium
    python导入自定义包
    About Me、
  • 原文地址:https://www.cnblogs.com/Cailf/p/11383419.html
Copyright © 2011-2022 走看看