API请求WaitingForActivation“尚未计算";错误 [英] API request WaitingForActivation "Not yet computed" error

查看:941
本文介绍了API请求WaitingForActivation“尚未计算";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自以下网站的Poloniex C#API代码: https://github.com/Jojatekok/PoloniexApi .Net

I'm using the Poloniex C# API code from: https://github.com/Jojatekok/PoloniexApi.Net

在我的控制台应用程序上,获取余额的请求正在运行,我进行了API调用,余额又回来了,但是在我的Windows Forms应用程序中,它没有等待余额的发生:

On my console application the request to get balances is working, i make the API call and the balances come back, but on my Windows Forms application it's not getting past waiting for the balances:

Id = 14, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"

使用此代码时:

PoloniexClient polo_client { get; set; }

private void Main(){
    polo_client = new PoloniexClient(ApiKeys.PublicKey, ApiKeys.PrivateKey);
    var balance_task = getLatestWalletAmounts();
    balance_task.Wait();

    // doesn't get past here on my Forms app

    if (balance_task.IsCompleted){
          // gets to here on my Console app
    }
}

// get wallet and startup amounts
async Task<IDictionary<string, Jojatekok.PoloniexAPI.WalletTools.IBalance>> getLatestWalletAmounts()
{ 
   // get wallet coin list 
   return await polo_client.Wallet.GetBalancesAsync();  
}

与我的控制台应用程序完全相同的代码,但是在Forms应用程序上任务未完成,而在Console应用程序上任务正在完成,我回来了:

It's the exact same code as my Console application, but on the Forms app the task is not completing and on the Console application it is completing and i'm getting back:

Id = 3, Status = RanToCompletion, Method = "{null}", Result = "System.Collections.Generic.Dictionary`2[System.String,Jojatekok.PoloniexAPI.WalletTools.IBalance]"

有什么暗示为什么相同的请求没有在我的Forms应用程序上完成,而是在我的Console应用程序上?我正在使用控制台和Forms应用程序中引用的完全相同的Poloniex C#项目与API进行交互.

Any hints as to why the same request isn't completing on my Forms application but it is on my Console app? I'm using the exact same Poloniex C# project referenced in my Console and Forms app to interact with the API.

两个项目中的API公钥均相同,并且两个项目中的API私钥均相同.

The API public key is the same in both projects and the API private key is the same in both projects.

推荐答案

您不能像这样混合使用异步代码和同步代码.通过调用.Wait,UI线程被卡住以等待任务完成,但是该任务实质上是试图在UI线程上调用",因此无法完成.结果:死锁.

You cannot mix async and synchronous code like this. By calling .Wait, the UI thread is stuck waiting for the task to finish, but the task is essentially trying to "Invoke" on the UI thread, so it cannot finish. Result: deadlock.

您可以看到有关基本问题的更多信息在这里.

一种选择,作为创可贴,是在await polo_client.Wallet.GetBalancesAsync()调用中使用ConfigureAwait(false);这将覆盖尝试返回UI线程的默认行为. (请注意,这意味着您将无法在await之后访问UI,因为它将在另一个线程上继续!)

One option, as a band-aid, is to use ConfigureAwait(false) on the await polo_client.Wallet.GetBalancesAsync() call; that will override the default behavior of trying to return to the UI thread. (Note that means you can't access the UI after the await, because it will be continuing on a different thread!)

我在这里写了一篇较长的文章,将异步代码引入UI应用程序.

这篇关于API请求WaitingForActivation“尚未计算";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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