using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
//using System.Threading.Tasks;
using System.IO;
using System.Collections; namespace ConsoleApplication2
{ class program
{
static void Main(string[] args)
{
Console.WriteLine("开始一个新的线程,名为次线程");
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
for (int i = ; i < ; i++)
{
Console.WriteLine("主线程:" + i);
Thread.Sleep();
}
Console.WriteLine("调用Join函数等待次线程结束");
//当次线程执行完毕后,Join阻塞调用线程,直到某个线程终止为止,本例为次线程
t.Join();
Console.WriteLine("线程执行完毕");
}
public static void ThreadProc()
{
for (int i = ; i < ; i++)
{
Console.WriteLine("ThreadPorc:{0}", i);
Thread.Sleep();//将当前进程阻塞指定的毫秒数
}
} }
}
static void Main(string[] args)
{
Thread t1 = new Thread(new ThreadStart(Thread1));
Thread t2 = new Thread(new ThreadStart(Thread2)); t1.Priority = ThreadPriority.BelowNormal ;
t2.Priority = ThreadPriority.Lowest ;
t1.Start();
t2.Start();
}
public static void Thread1()
{
for (int i = ; i < ; i++)
{//每运行一个循环就写一个“1”
dosth();
Console.Write("");
}
}
public static void Thread2()
{
for (int i = ; i < ; i++)
{//每运行一个循环就写一个“2”
dosth();
Console.Write("");
}
}
public static void dosth()
{//用来模拟复杂运算
for (int j = ; j < ; j++)
{
int a=;
a = a*a*a*a;
}
}

最新文章

  1. sublime text 3 3083 注册码
  2. 数据库SQL优化大总结之 百万级数据库优化方案
  3. iOS 判断字符串是否为空
  4. 实现jquery.ajax及原生的XMLHttpRequest调用WCF服务的方法
  5. 【2016-10-11】Linux系统常用的关机或重启命令shutdown、reboot、halt、poweroff、init 0及init 6的联系与区别
  6. Android Activity的加载模式和onActivityResult方法之间的冲突
  7. 0414-复利计算器6.0.Release
  8. ASP.NET MVC4中使用Ninject
  9. awk 传入外部参数
  10. Mysql 批量建表存储过程
  11. root 密码丢失后的重新设置
  12. 为什么我选择使用 Blocks(块)
  13. JQ 日期格式化
  14. 在线程中进行读取并写入文件和wenjia
  15. asp net 编程问题 实现下一篇 和上一篇效果
  16. 架构漫谈系列(2) 封装(Encapsulation)
  17. poj1067威佐夫博奕
  18. JAVA 平时作业一
  19. 从原型链探究Javascript这么火的原因
  20. TCP/IP协议(一)网络基础知识 网络七层协议

热门文章

  1. tensorflow中使用tf.ConfigProto()配置Session运行参数&&GPU设备指定
  2. 每天一个linux命令(15):head命令
  3. js中call apply方法的使用介绍
  4. Composer + thinkphp5.1安装与使用
  5. jQuery 实现最简单的form表单提交 Loding 功能
  6. @property_@synthesize 配套使用
  7. maven配置的问题,maven的环境变量配置
  8. iOS开发之---KVC全解
  9. C Primer Plus学习笔记(六)- C 控制语句:分支和跳转
  10. DataGridView风格设置