小编Ara*_*ami的帖子

为所有服务器端代码调用ConfigureAwait的最佳实践

当你有服务器端代码(即一些ApiController)并且你的函数是异步的 - 所以它们返回Task<SomeObject>- 你认为最好的做法是等待你调用的函数ConfigureAwait(false)吗?

我已经读过它更高效,因为它不必将线程上下文切换回原始线程上下文.但是,使用ASP.NET Web Api,如果您的请求是在一个线程上进行的,并且等待某些函数和调用ConfigureAwait(false),则可能会在返回ApiController函数的最终结果时将您置于不同的线程上.

我在下面输入了一个我正在谈论的例子:

public class CustomerController : ApiController
{
    public async Task<Customer> Get(int id)
    {
        // you are on a particular thread here
        var customer = await SomeAsyncFunctionThatGetsCustomer(id).ConfigureAwait(false);

        // now you are on a different thread!  will that cause problems?
        return customer;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# task-parallel-library async-await asp.net-web-api

517
推荐指数
4
解决办法
18万
查看次数

WampSharp无法连接到Poloniex?

这是使用WampSharp的最新预发布版本的非常简单的代码:

        var channelFactory = new DefaultWampChannelFactory();
        var channel = channelFactory.CreateMsgpackChannel("wss://api.poloniex.com", "realm1");
        await channel.Open();

        var realmProxy = channel.RealmProxy;

        Console.WriteLine("Connection established");

        int received = 0;
        IDisposable subscription = null;

        subscription =
            realmProxy.Services.GetSubject("ticker")
                      .Subscribe(x =>
            {
                Console.WriteLine("Got Event: " + x);

                received++;

                if (received > 5)
                {
                    Console.WriteLine("Closing ..");
                    subscription.Dispose();
                }
            });

        Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

但是不起作用,订阅中的代码永远不会运行.也尝试过CreateJsonChannel,这也不起作用.

什么想法可能是错的?

c# wamp wampsharp

8
推荐指数
1
解决办法
1787
查看次数

WinRT中的全球调度员?

我有一些看起来像这样的WP7代码:



using System.Windows;
using System.Windows.Threading;

public static class GlobalDispatcher
{
    public static Dispatcher Current { get { return Deployment.Current.Dispatcher; } }
}

Run Code Online (Sandbox Code Playgroud)

WinRT中的等价物是什么?是否没有全局可访问的Dispatcher(或CoreDispatcher)对象?

xaml microsoft-metro windows-8 windows-runtime winrt-xaml

6
推荐指数
2
解决办法
2925
查看次数