Tasks in parallel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading.Tasks;
using System.Threading;
using System.IO;
using Microsoft.SqlServer.Dts.Runtime; struct Response
{
public bool DTSResult { get; set; }
public string Message { get; set; }
} public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } Response ExecuteWorkA()
{
bool flagA = false; try
{
//Thread.Sleep(16000);
string pkgLocation;
Package pkg;
Application app;
DTSExecResult pkgResults; pkgLocation =
@"C:\Users\xxxxxxxxxx\Documents\Visual Studio 2008\projects\Integration Services Project1\Integration Services Project1\Package.dtsx";
app = new Application();
pkg = app.LoadPackage(pkgLocation, null);
pkgResults = pkg.Execute();
flagA = pkgResults == DTSExecResult.Success; //throw new Exception("err");
}
catch (Exception ex)
{
flagA = false;
}
return new Response { DTSResult = flagA };
} Response ExecuteWorkB()
{
bool flagB = false;
try
{
Thread.Sleep(14000);
flagB = true;
//throw new Exception("error");
}
catch (Exception ex)
{
flagB = false;
}
return new Response { DTSResult = flagB };
} Response ExecuteWorkC()
{
bool flagC = false;
Thread.Sleep(17000);
flagC = true;
return new Response { DTSResult = flagC};
} protected void Button1_Click(object sender, EventArgs e)
{
List<Func<Response>> lst = new List<Func<Response>>();
lst.Add(ExecuteWorkA);
lst.Add(ExecuteWorkB);
lst.Add(ExecuteWorkC); List<Response> result = new List<Response>(); Action act = () =>
{ Parallel.ForEach(lst, (func) =>
{
result.Add(func());
}); bool isFailed = false;
foreach (Response item in result)
{
if (!item.DTSResult)
{
isFailed = true;
break;
}
} if(result.Count > 0 )
File.AppendAllText(@"D:\Temp\log.txt", string.Format("{0} {1} ", DateTime.Now, isFailed ? "Failed!" : "Suceed!")); }; act.BeginInvoke(null, null); //for better, have callback method... }
}
Tasks in parallel的更多相关文章
- 并行编程多线程之Parallel
		1.简介 随着多核时代的到来,并行开发越来越展示出它的强大威力!使用并行程序,充分的利用系统资源,提高程序的性能.在.net 4.0中,微软给我们提供了一个新的命名空间:System.Threadin ... 
- Introduction to Parallel Computing
		Copied From:https://computing.llnl.gov/tutorials/parallel_comp/ Author: Blaise Barney, Lawrence Live ... 
- Why you should use async tasks in .NET 4.5 and Entity Framework 6
		Improve response times and handle more users with parallel processing Building a web application usi ... 
- scrapy之parallel
		Limiting Parallelism jcalderone May 22nd, 2006 This blog has moved! Read this post and its comments ... 
- C++11: Multi-core Programming – PPL Parallel Aggregation Explained
		https://katyscode.wordpress.com/2013/08/17/c11-multi-core-programming-ppl-parallel-aggregation-expla ... 
- Android中AsyncTask分析--你所不注意的坑
		AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作,并提供接口反馈当前异步执行的程度(可以通过接口实现UI进度更新),最后反馈执行的结果给UI ... 
- Java 8新特性终极指南
		目录结构 介绍 Java语言的新特性 2.1 Lambdas表达式与Functional接口 2.2 接口的默认与静态方法 2.3 方法引用 2.4 重复注解 2.5 更好的类型推测机制 2.6 扩展 ... 
- Docker on YARN在Hulu的实现
		这篇文章是我来Hulu这一年做的主要工作,结合当下流行的两个开源方案Docker和YARN,提供了一套灵活的编程模型,目前支持DAG编程模型,将会支持长服务编程模型. 基于Voidbox,开发者可以很 ... 
- Android AsyncTask 源码解析
		1. 官方介绍 public abstract class AsyncTask extends Object java.lang.Object ↳ android.os.AsyncTask&l ... 
随机推荐
- CxGrid如何实现导出Excel 功能
			ExportGrid4ToEXCEL 这个老的版本用的,新的版本引用 cxGridExportLink 这个单元 uses Windows, Messages, SysUtils, Variant ... 
- hdu1024(最大m串子序列)
			m的范围没给,很坑爹 Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ... 
- 【POJ3621】Sightseeing Cows 分数规划
			[POJ3621]Sightseeing Cows 题意:在给定的一个图上寻找一个环路,使得总欢乐值(经过的点权值之和)/ 总时间(经过的边权值之和)最大. 题解:显然是分数规划,二分答案ans,将每 ... 
- linux系统安装jdk及配置环境变量
			OpenJdk8安装: sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openj ... 
- 记一个在docker中运行多线程event_loop.run_forever()的bug
			问题简介 我写爬虫,用到了asyncio相关的事件循环,新建了一个线程去run_forever(),在docker中运行.后来程序有异常,主线程挂了,但是竟然不报错.查了很久,才找出来. 如果你新建一 ... 
- Vscode 调试 C 语言时数组值无法显示的问题
			使用 Vscode 的 Gdb 扩展调试 C 语言时,发现数组变量在 变量列表里面中显示为指针,且只显示为其第一个元素的值,无法看到所有元素的值. 如图所示: 解决: 假设有一个元素个数为10的数组v ... 
- 面试之二:Redis是单线程还是多线程?以及处理模型。
			Redis是单线程还是多线程?以及处理模型. 线程:单线程 处理模型:参考书<Redis 设计与实现>P151-152 .字符串 类型的多分支 Int month =5; Switch 二.方法meth ... 
- Python--进阶处理5
			# 使用路径名来获取文件名,目录名,绝对路径等import ospath = r'F:\myProject\lean\a'# Get the last component of the pathbas ... 
- SignalR循序渐进(三)简易的集群通讯组件
			上一篇演示了泛型Hub的实现,微软于6月17日更新了SignalR 2.1.0,然后自带了泛型Hub,于是就不需要自己去实现了…(微软你为啥不早一个月自带啊…).不过没关系,SignalR出彩之处不在 ... 
