多线程并行搜索文件

usingSystem;
02 usingSystem.IO;
03 usingSystem.Linq;
04 usingSystem.Threading.Tasks;
05
06 classProgram
07 {
08 staticvoidMain()
09 {
10 // Return a value type with a lambda expression
11 Task<int> task1 = Task<int>.Factory.StartNew(() => 1);
12 inti = task1.Result;
13
14 // Return a named reference type with a multi-line statement lambda.
15 Task<Test> task2 = Task<Test>.Factory.StartNew(() =>
16 {
17 strings =".NET";
18 doubled = 4.0;
19 returnnewTest { Name = s, Number = d };
20 });
21 Test test = task2.Result;
22
23 // Return an array produced by a PLINQ query
24 Task<string[]> task3 = Task<string[]>.Factory.StartNew(() =>
25 {
26 stringpath =@"C:\users\public\pictures\";
27 string[] files = Directory.GetFiles(path);
28
29 var result = (from fileinfiles.AsParallel()
30 let info =newFileInfo(file)
31 where info.Extension ==".jpg"
32 select file).ToArray();
33
34 returnresult;
35 });
36
37 foreach(var nameintask3.Result)
38 Console.WriteLine(name);
39
40 }
41 classTest
42 {
43 publicstringName {get;set; }
44 publicdoubleNumber {get;set; }
45
46 }
47 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值