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的更多相关文章

  1. 并行编程多线程之Parallel

    1.简介 随着多核时代的到来,并行开发越来越展示出它的强大威力!使用并行程序,充分的利用系统资源,提高程序的性能.在.net 4.0中,微软给我们提供了一个新的命名空间:System.Threadin ...

  2. Introduction to Parallel Computing

    Copied From:https://computing.llnl.gov/tutorials/parallel_comp/ Author: Blaise Barney, Lawrence Live ...

  3. 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 ...

  4. scrapy之parallel

    Limiting Parallelism jcalderone May 22nd, 2006 This blog has moved! Read this post and its comments ...

  5. C++11: Multi-core Programming – PPL Parallel Aggregation Explained

    https://katyscode.wordpress.com/2013/08/17/c11-multi-core-programming-ppl-parallel-aggregation-expla ...

  6. Android中AsyncTask分析--你所不注意的坑

    AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作,并提供接口反馈当前异步执行的程度(可以通过接口实现UI进度更新),最后反馈执行的结果给UI ...

  7. Java 8新特性终极指南

    目录结构 介绍 Java语言的新特性 2.1 Lambdas表达式与Functional接口 2.2 接口的默认与静态方法 2.3 方法引用 2.4 重复注解 2.5 更好的类型推测机制 2.6 扩展 ...

  8. Docker on YARN在Hulu的实现

    这篇文章是我来Hulu这一年做的主要工作,结合当下流行的两个开源方案Docker和YARN,提供了一套灵活的编程模型,目前支持DAG编程模型,将会支持长服务编程模型. 基于Voidbox,开发者可以很 ...

  9. Android AsyncTask 源码解析

    1. 官方介绍 public abstract class AsyncTask extends Object  java.lang.Object    ↳ android.os.AsyncTask&l ...

随机推荐

  1. [深入理解Android卷一全文-第八章]深入理解Surface系统

    由于<深入理解Android 卷一>和<深入理解Android卷二>不再出版.而知识的传播不应该由于纸质媒介的问题而中断,所以我将在CSDN博客中全文转发这两本书的全部内容. ...

  2. 论坛模块__发帖时使用FCKeditor

    论坛模块__发帖时使用FCKeditor 测试 <html> <head> <meta http-equiv="content-type" conte ...

  3. Spring_day03--课程安排_基于aspectj的注解aop_Spring的jdbcTemplate操作

    Spring_day03 上节内容回顾 今天内容介绍 基于aspectj的注解aop Spring的jdbcTemplate操作 增加 修改 删除 查询 Spring配置c3p0连接池和dao使用jd ...

  4. Spring_day02--AOP概念、原理、操作术语

    AOP概念 hibernate要手动进行事务操作,在spring中通过配置文件来配置事务 1 aop:面向切面(方面)编程,扩展功能不修改源代码实现 2  AOP采取横向抽取机制,取代了传统纵向继承体 ...

  5. 现代3D图形编程学习-关于本书

    关于这本书 三维图像处理硬件很快成为了必不可少的组件.很多操作系统能够直接使用三维图像硬件,有些甚至要求需要有3D渲染能力的硬件.同时对于日益增加的手机系统,3D图像硬件,也成为了它们的必备特征. 对 ...

  6. 160506、Spring mvc新手入门(11)-返回json 字符串的其他方式

    Spring MVC返回 json字符串的方式有很多种方法,这里介绍最简单,也是最常使用的两种方式 一.使用  PrintWriter printWriter  直接输出字符串到返回结果中    不需 ...

  7. [报错]Unable to simultaneously satisfy constraints

    项目中自定义Cell,控件使用autoLayout来设置约束,发现运行页面表现正常,但是控制台报如下错误: Unable to simultaneously satisfy constraints. ...

  8. POJ1470Closest Common Ancestors 最近公共祖先LCA 的 离线算法 Tarjan

    该算法的详细解释请戳: http://www.cnblogs.com/Findxiaoxun/p/3428516.html #include<cstdio> #include<alg ...

  9. embedded-redis在单元测试中的使用

    1 背景 参考链接:https://github.com/kstyrc/embedded-redis 2 使用 2.1 引入依赖 <dependency> <groupId>c ...

  10. JSON 序列化与反序列化(二)使用TypeReference 构建类型安全的异构容器

    1. 泛型通常用于集合,如Set和Map等.这样的用法也就限制了每个容器只能有固定数目的类型参数,一般来说,这也确实是我们想要的. 然而有的时候我们需要更多的灵活性,如数据库可以用任意多的Column ...