有人可以用最简洁的方式向我解释这个问题 [英] Can someone explain this to me in the detailest way they can

查看:67
本文介绍了有人可以用最简洁的方式向我解释这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我得到这是一个异步任务我之前使用过基本的异步任务来做简单的任务但是

我想要做的是理解返回类型和如何实现它c#代码

我已经阅读了十几篇关于解释异步任务和界面的文章,我似乎无法绕过它。



now i get this is a async TASK i've used basic async task before to do simple task but
what im trying to do is understanding the return type and how to implement it c# code
ive read a dozen or so articles on explaining async task and interfacers i just cant seem to wrap my head around it.

Task<IGuildUser> AddGuildUserAsync(ulong userId, string accessToken, Action<AddGuildUserProperties> func = null, RequestOptions options = null)







*文件

h ttps://docs.stillu.cc/api/Discord.IGuild.html#Discord_IGuild_AddGuildUserAsync_System_UInt64_System_String_System_Action_Discord_AddGuildUserProperties__Discord_RequestOptions_



我尝试过:



尝试使用discord API寻求帮助。 />
阅读并观看有关异步任务和界面的视频,但无法绕过它




*documentation
https://docs.stillu.cc/api/Discord.IGuild.html#Discord_IGuild_AddGuildUserAsync_System_UInt64_System_String_System_Action_Discord_AddGuildUserProperties__Discord_RequestOptions_

What I have tried:

tried discord API for help.
read and watch videos regarding async task and interface but cant wrap my head around it

推荐答案

带签名的方法:



A method with the signature:

Task<iguilduser> AddGuildUserAsync(ulong userId, string accessToken, Action<addguilduserproperties> func = null, RequestOptions options = null)





具有返回类型:Task< ; iguilduser> ;,将IGuildUser实现包装在Task对象中。



我想你想要获得的是IGuildUser,所以你有3个选择:< br $>




Has the return type: Task<iguilduser>, with the IGuildUser implementation wrapped inside the Task object.

What you want to obtain, I assume, is the IGuildUser, so you have 3 options:

IGuildUser user = AddGuildUserAsync(ulong userId, string accessToken, Action<addguilduserproperties> func = null, RequestOptions options = null).Result;





这将同步运行,并不是异步的真正原因。


或者,你'等待'menthod,它有效地做了类似的事情,但是会异步运行,并且只能在另一个异步方法中完成:





This will run synchronously, and is not really what async is for.

Alternatively, you 'await' the menthod, which effectively does a similar thing, but will run asynchronously, and can only be done inside another async method:

IGuildUser user = await AddGuildUserAsync(ulong userId, string accessToken, Action<addguilduserproperties> func = null, RequestOptions options = null)





第三个选项,如果你想从非ansync方法运行,可能会启动它在另一项任务中:





The third option, if you want to run from a non-ansync method, may be to fire it up in a separate task:

IGuildUser user = Task.Run(() => AddGuildUserAsync(ulong userId, string accessToken, Action<addguilduserproperties> func = null, RequestOptions options = null).Result;


这篇关于有人可以用最简洁的方式向我解释这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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