zoukankan      html  css  js  c++  java
  • 使用线程池

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Threading;
    using UnityEngine;
    using Random = System.Random;
    
    public class MyThreadManger : MonoBehaviour {
        Hashtable hashtable = new Hashtable();
        private int m_iParam=0;//随便一个类型的参数
        private static string name = "1";//随便一个类型的参数
        void Start()
        {
    
                ThreadPool.QueueUserWorkItem(new WaitCallback(MyMethod), name);//将方法添加进线程池,并传入参数
                ThreadPool.QueueUserWorkItem(new WaitCallback(MyMethod2), name);//将方法添加进线程池,并传入参数
    
        }
        private void MyMethod(object param)
        {
            Random ran = new Random(100);
          
            for (int i = 0; i < 100; i++)
            {
                try
                {
                    hashtable[i] = param;
                    param = Convert.ToString(ran.Next());
                    Debug.Log("开了一个线程:" + hashtable[i + "11~"].ToString());
                    Thread.Sleep(100);
                }
                catch (Exception ex)
                {
    
                    Debug.LogWarning(ex);
                }   
            }        
        }
    
        private void MyMethod2(object param)
        {
            Random ran = new Random(200);
            for (int i = 0; i < 100; i++)
            {
                try
                {
                    hashtable[i + "11~"] = param;
                    param = Convert.ToString(ran.Next(2));
                    Debug.Log("开了第二个线程:" + hashtable[i + "11~"].ToString());
                    Thread.Sleep(100);
                }
                catch (Exception ex)
                {
    
                    Debug.LogWarning(ex);
                }
              
            }
        }
    }
    

      

  • 相关阅读:
    jmeter在Windows下安装(含插件安装)
    Jenkins中agent的使用
    Jenkins自动化测试脚本的构建
    Python在Linux下编译安装
    Jenkins项目构建运行
    VIM不正常退出产生的swp文件
    SSI服务器端包含注入
    【强网杯2019】随便注
    判断网站CMS
    windows基础
  • 原文地址:https://www.cnblogs.com/yangxiaohang/p/8617694.html
Copyright © 2011-2022 走看看