创建多线程,并带参数!

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading; namespace ThreadProcess
{
class Program
{
static void Main(string[] args)
{
string path = @"c:\test\";
string[] Dirs = Directory.GetFiles(path, "*.txt");
//创建相应线程数
ArrayList al = new ArrayList();
foreach(string s in Dirs)
{
if (!File.Exists(s.Substring(, s.LastIndexOf('.')) + ".lock"))
al.Add(s);
}
Thread[] t = new Thread[al.Count];
for (int i = ; i <al.Count; i++)
{
t[i] = new Thread(new ParameterizedThreadStart(Process));
t[i].Start(Dirs[i].ToString());
}
} static void Process(object fileName)
{
string procFile = (string)fileName;
string lockFile = procFile.Substring(, procFile.LastIndexOf('.')) + ".lock";
//if (File.Exists(lockFile))
//{
// return;
//}
//else
//{
// FileStream fs = new FileStream(lockFile, FileMode.CreateNew);
// fs.Close(); //}
FileStream fs = new FileStream(lockFile, FileMode.CreateNew);
fs.Close(); while (true)
{
//这里作相应处理工作
Console.Write(lockFile);
Thread.Sleep();
}
File.Delete(lockFile);
File.Delete(procFile); }
}
}

最新文章

  1. switch与ifelse的效率问题
  2. C#调用SQL Server分页存储过程
  3. unity 播放音乐
  4. C#数组的排序
  5. windows下svn自动更新
  6. js风格技巧
  7. 单位内部DNS架设及域名解析服务
  8. python wsgi
  9. 二维动态规划——Palindrome
  10. MybatisGenerator生成的mapper 少了识别主键的方法 byPrimaryKey()
  11. 洛谷P1774 最接近神的人_NOI导刊2010提高(02)(求逆序对)
  12. kvm qemu ,ubuntu debian rootfs 通过qemu复现路由器漏洞
  13. Hibernate+struct web项目问题总结
  14. L236
  15. Microsoft - Union Two Sorted List with Distinct Value
  16. AJAX学习必备三本书
  17. Arduino + SmartAirFilter 制作智能感应的 PM 空气净化器
  18. Eclipse+ADT+Android SDK 搭建安卓开发环境(版权属于forever-z)
  19. SpringBoot入门之spring-boot-maven-plugin
  20. 51nod-1636-dp

热门文章

  1. java jdk动态代理(proxy)
  2. SpringBoot使用qq邮箱发送邮件
  3. [已解决]ValueError: row index was 65536, not allowed by .xls format
  4. git 多用户多仓库配置
  5. 【vue】iView-admin2.0动态菜单路由
  6. PHP按权重随机
  7. 使用axios 的post请求下载文件,
  8. jeecg字典表—报表配置(popup弹框)
  9. 关于spring boot中 EmbeddedServletContainerCustomizer
  10. Android Studio自定义注释模板