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. Window发声函数Beep、MessageBeep

     C++ Code  1234567891011   WINBASEAPI BOOL WINAPI Beep(__in DWORD dwFreq,      __in DWORD dwDuration ...

  2. (转)有关thread线程

    Python 标准库提供了 thread 和 threading 两个模块来对多线程进行支持.其中, thread 模块以低级.原始的方式来处理和控制线程,而 threading 模块通过对 thre ...

  3. 编程之美 set 7 求数组中的最长递增子序列

    解法 1. 假设在目标数组 array[] 的前 i 个元素中, 最长递增子序列的长度为 LIS[i] 那么状态转移方程为 LIS[i] = max(1, LIS[k]+1) array[i+1] & ...

  4. 第九篇:使用 AdaBoost 元算法提高分类器性能

    前言 有人认为 AdaBoost 是最好的监督学习的方式. 某种程度上因为它是元算法,也就是说它会是几种分类器的组合.这就好比对于一个问题能够咨询多个 "专家" 的意见了. 组合的 ...

  5. 使用js里面的迭代器filter实现数组去重

    实现数组去重的方法很多,最原始的方法是一个值一个值的去遍历,写到空数组里面: let r=[],arr = ['a', 'b', 'c', 'a']; for(var i=0,len=arr.leng ...

  6. c++11 lambda(了解)

    this->send_change_equip = ([this](ChangeEquipPT channge) { send_cmd(s2c_change_equip, &channg ...

  7. 编写jsp动态网页

    默认情况下,jsp网页必须保存在TOMCAT_HOME/webapps 目录下才能被客户请求. JSP网页的主题仍然是html标签,在需要显示动态数据的地方添加<%%>标记,在其中编写合法 ...

  8. 《从零开始学Swift》学习笔记(Day67)——Cocoa Touch设计模式及应用之MVC模式

    原创文章,欢迎转载.转载请注明:关东升的博客 MVC(Model-View-Controller,模型-视图-控制器)模式是相当古老的设计模式之一,它最早出现在Smalltalk语言中.现在,很多计算 ...

  9. vector排序问题<unresolved overloaded function type>

    要对vector中的自定义类型进行排序,首先需要提供一个函数bool comp(const Interval & a, const Interval & b) 来定义类型的排序准则 然 ...

  10. java前后台开发之后台自动上传下载

    package downloadTest; import java.io.BufferedReader; import java.io.File; import java.io.FileInputSt ...