多线程Thread例子
来源:互联网 发布:php webshell 编辑:程序博客网 时间:2024/05/07 15:34
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Threading; //引入命名空间
namespace ConsoleApplication2
{
class Program
{
static int s;
static void Main(string[] args)
{
s =int.Parse( Console.ReadLine());
Thread thisThread = Thread.CurrentThread;//获取当前线程
thisThread.Name = "Main Thread";
ThreadStart start = new ThreadStart(StartMethod); //实例化一个委托 线程委托
Thread workerThead = new Thread(start);//创建一个线程
workerThead.Name = "Work Thread";
workerThead.Start();
workerThead.Priority = ThreadPriority.Highest;//设置线程优先级
DisplayNumbers();
Console.ReadLine();
}
static void StartMethod()
{
DisplayNumbers();
Console.WriteLine("Worker Thread Finished");
}
static void DisplayNumbers()
{
for (int i = 0; i < s; i++)
{
Console.WriteLine(Thread.CurrentThread.Name+":"+i);
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Threading; //引入命名空间
namespace ConsoleApplication2
{
class Program
{
static int s;
static void Main(string[] args)
{
s =int.Parse( Console.ReadLine());
Thread thisThread = Thread.CurrentThread;//获取当前线程
thisThread.Name = "Main Thread";
ThreadStart start = new ThreadStart(StartMethod); //实例化一个委托 线程委托
Thread workerThead = new Thread(start);//创建一个线程
workerThead.Name = "Work Thread";
workerThead.Start();
workerThead.Priority = ThreadPriority.Highest;//设置线程优先级
DisplayNumbers();
Console.ReadLine();
}
static void StartMethod()
{
DisplayNumbers();
Console.WriteLine("Worker Thread Finished");
}
static void DisplayNumbers()
{
for (int i = 0; i < s; i++)
{
Console.WriteLine(Thread.CurrentThread.Name+":"+i);
}
}
}
}
- 多线程Thread例子
- Thread - 多线程更新(update)数据库表的例子
- Java多线程基础-2-简单继承Thread,实现Runnable例子
- thread例子
- Thread例子
- 多线程Thread
- 多线程 Thread
- 多线程Thread
- 多线程-thread
- Thread-多线程
- 多线程Thread
- 多线程THread
- Thread多线程
- Thread多线程
- 【Boost】boost库中thread多线程详解6——线程组简单例子
- 【Boost】boost库中thread多线程详解7——wait与timed_wait简单例子
- boost库中thread多线程详解6——线程组简单例子
- 【Boost】boost库中thread多线程详解6——线程组简单例子
- 测试测试
- 按条件打印的问题
- dtree
- MINE类型
- Google Map Android API v2
- 多线程Thread例子
- 压缩感知简介
- 当上传文件的时候自动过滤掉其他格式的文件(ie8 ie9问题待解决)
- shl 和 shr
- [设计模式笔记]三. 行为型模式--16. Command模式(命令模式)(一)
- dTree的分析和二次开发,ajax加载dtree节点(下)(转)
- [Android]网络资源下载时断点续传的实现
- python字典作为统计记录工具
- 【Cocosd2d实例教程二】地图编辑器Tiled的安装使用