惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - neverlost

客户端开发杂记 html5 元素 来自 nativeformelements.com 闲扯,面向对象的ext4中的一些事儿1 Ext 4 beta1 发布似乎仍不给力 .net 下比较蛋疼的word 表格转excel表格 浅述教学上基于Media Player的视频切片方式 webservice传输数据量较大的情况的解决方案 - neverlost - 博客园 vs2010中文版+codesmith 5.2 安装失败 转的 winform开发连接webservice中单向证书 .net下开发windows服务的经验 .net 写的 webservice 给java调用 ext中使用tab方式 ext做列表页面关于查询多行的办法 关于架构的问题 ext的grid 获取页面内容方式 - neverlost - 博客园 微软.net下 charting 要注意的事情 - neverlost .net 获取 其他类型的webservice的方式以及看法 2条路 代码生成 or 配置 2.1 2条路 代码生成 or 配置 2
现场保障系统开发过程中增加并行处理(一)
neverlost · 2010-07-16 · via 博客园 - neverlost

在现场保障系统开发中,考虑到从客户端获取webservice比较慢以及性能问题,打算采用多线程异步处理机制,希望能够增强用户体验,不至于在加载窗体的时候导致假死机现象.于是先实现了多线程的功能:

在业务层增加了专门处理多线程的类(AsyncHelper)

但是考虑到我们现在采用的框架是.net framework 4.0的版本,于是增加了并行处理机制.

并行处理机制使得我们更多的把重点放在业务上,我们没有象多线程那么单独抽取出来一个类然后再调用,而是分散在具体的业务中.

并行处理机制首先是需要考虑好怎么样划分这个并行处理的任务模块,如果划分的不好,那么相互间会有影响,性能反而下降.

并且并行处理本身就是多线程的,而且封装的更好.

一般如下进行操作:

首先是划分你的功能:

           Action task1 = new Action(() =>
            {
              GetData1(Thread.CurrentThread.ManagedThreadId.ToString());
                                  
            });
           Action task2 = new Action(() =>
           {
               GetData2(Thread.CurrentThread.ManagedThreadId.ToString());
               
           });
           Action task3 = new Action(() =>
           {
               GetData3(Thread.CurrentThread.ManagedThreadId.ToString());
              
           });
然后是调用

          //这是第一种方式:

          var tasks = new Action[] { () => task1(), () => task2(), () => task3() };

           // System.Threading.Tasks.Parallel.Invoke - 并行调用多个任务
           System.Threading.Tasks.Parallel.Invoke(tasks);

//这是第2种方式

          Task task0 = new Task(() =>
           {
               Task.Factory.StartNew(() => task1());
               Task.Factory.StartNew(() => task2());
               Task.Factory.StartNew(() => task3());
           });
           task0.Start();

如果Task<T> task0 = new Task<T>()

那么 可以获取该task的返回值 task0.Result