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 ...
随机推荐
- ip地址查询系统和CMD查询的结果不一样
由于cmd输入 ipconfig查看的IP是局域网内网IP,而用ip地址查看器查看是公网上网的ip地址.所以不一样. 查询内网ip: windows系统: 开始--运行--cmd,命令行输入: ipc ...
- Struts2_day04--课程介绍_Struts2拦截器概述&底层原理_重要的概念
Struts2_day04 上节内容 今天内容 Struts2拦截器概述 拦截器底层原理 重要的概念 自定义拦截器 自定义登录拦截器 Struts2的标签库 Struts2表单标签(会用) Strut ...
- m2014-software->Word2010发布博客文章至Cnblogs
转自:http://www.cnblogs.com/xfiver/archive/2011/12/26/2301591.html 昨夜喝醉,今天早起梳理情绪,看下如何使用word2010直接写cnbl ...
- 在 Linux 中安装 Lighttpd Web 服务器
Lighttpd 是一款开源 Web 服务器软件.Lighttpd 安全快速,符合行业标准,适配性强并且针对高配置环境进行了优化.相对于其它的 Web 服务器而言,Lighttpd 占用内存更少:因其 ...
- rimraf删除gulp的模块插件
1.安装:npm install -g rimraf(全局安装),如果安装了cnpm,也可使用cnpm install -g rimraf 命令 2.使用:先定位目标文件夹的父级目录,然后命令行输入r ...
- 动态加载script文件
动态加载script文件: http://www.cnblogs.com/skykang/archive/2011/07/21/2112685.html
- 在 Java 应用程序中绑定 Bean 和数据
本指南介绍了 NetBeans IDE 对 Java 应用程序中 Bean 绑定和数据绑定的支持. 要学完本教程,您需要具备以下软件和资源. 软件或资源 要求的版本 NetBeans IDE 版本 7 ...
- Piwik网站访问统计软件安装
Piwik是一个PHP和MySQL的开放源代码的Web统计软件. 它给你一些关于你的网站的实用统计报告,比如网页浏览人数, 访问最多的页面, 搜索引擎关键词等等… Piwik拥有众多不同功能的插件,你 ...
- Code Forces 645C Enduring Exodus
C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...
- Servlet------>jsp自定义标签3(不显示余下jsp内容)
2.自定义标签控制,jsp页面余下标签是否继续执行 EndTag.java package tag; import javax.servlet.jsp.JspException; import jav ...