C#4有任何好的异步工作流模式吗? [英] Any good async workflow patterns for C# 4?

查看:67
本文介绍了C#4有任何好的异步工作流模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能指出我一些用于处理C#中异步工作流的模式吗?我知道这很快就会在C#5中实现,但是我想知道是否有人已经在C#4中实现了近似相同的效果?

Can anyone point me to some patterns for handling async workflows in C#? I know this is coming soon in C# 5 but I was wondering if anyone had already done an implementation in C# 4 that approximates the same effects?

基本上,我在Silverlight 4中编写了很多异步代码,如下所示:

Basically I'm writing a lot of async code in Silverlight 4 like this:

CallService(
    (service) => service.DoSomething(1, 2, 3),
    (response) =>
    {
        // some local code

        // need to call another service async
        CallService(
            (service) => service.DoSomethingElse(4, 5, 6),
            (response) =>
            {
                // even more nested async calls, you get the idea...
            }
        )
    }
);

嵌套的回调正传给我.我非常喜欢F#提供异步工作流来处理此问题的方式,因为最终您编写的代码看起来和感觉都是同步的,这正是我真正想要的.

The nested callbacks are getting to me. I really like the way F# provides async workflows to handle this, as you end up writing code that looks and feels synchronous, which is what I really want.

推荐答案

我们基于以下几组文章实现了一个异步库:

We have implemented an async library based on the following set of articles:

http://www.codeproject.com/KB/silverlight/ConsumingWCFServiceWithou.aspx http://www.codeproject.com/KB/silverlight/FixingAllAsync.aspx

http://www.codeproject.com/KB/silverlight/ConsumingWCFServiceWithou.aspx http://www.codeproject.com/KB/silverlight/FixingAllAsync.aspx

请特别注意本文的第2部分,该部分描述了如何简化异步WCF服务调用.作者介绍了一种基于协程使用异步服务的方法.很棒的文章.

Pay particular attention to Part 2 of the article which describes how to simplify async WCF service calls. The author describes an approach to the consumption of asynchronous services based on coroutines. A fantastic article.

这篇关于C#4有任何好的异步工作流模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆