简体   繁体   English

从Visual Studio 2010中的WCF异步调用返回值

[英]Return value from wcf async call in Visual Studio 2010

I want to get the value from a wcf async call. 我想从wcf异步调用获取值。

public DateTime currentDateTime;
private void GetDateTime()
    {
        var client = new WcfClient();
        client.GetCurrentDateTimeCompleted -= ClientGetCurrentDateTimeCompleted;
        client.GetCurrentDateTimeCompleted += ClientGetCurrentDateTimeCompleted;
        client.GetCurrentDateTimeAsync();
    }

    private void ClientGetCurrentDateTimeCompleted(object sender, GetCurrentDateTimeCompletedEventArgs args)
    {
        try
        {
            if (args.Error == null && args.Result != null)
            {
                currentDateTime = args.Result;
            }
        }

To call this method. 调用此方法。 I use GetDateTime . 我使用GetDateTime My question is the code didn't reach the method at all in the debug mode. 我的问题是代码在调试模式下根本没有达到方法。 The result time is Date = {1/1/0001 12:00:00 AM} . 结果时间是Date = {1/1/0001 12:00:00 AM}

I know I call it synchronously. 我知道我叫它同步。 But how to get it in the debug model? 但是如何在调试模型中获取它呢?

The easiest way is putting a breakpoint at the first line of the async method and pressing F5, the debugger should stop there and you can debug it. 最简单的方法是在async方法的第一行放置一个断点,然后按F5键,调试器应在此处停止并进行调试。

See here. 这里

Also MSDN has the document. MSDN也有该文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM