简体   繁体   English

为异步C#.net编写回调函数

[英]Writing a callback function for async c#.net

I am using Kinvey for my storage 我正在使用Kinvey进行存储

The callback for a non Async function is written as shown 非异步 函数的回调如下所示

myClient.User().create(myUserName, myPassword, new KinveyUserCallback(){...});

how do i do it if I was using an Async function ? 如果我正在使用异步 功能,该怎么办?

myClient.User().createAsync(myUserName, myPassword);

Im interested in the onError callback to check if the user already exists. 我对onError回调感兴趣,以检查用户是否已经存在。

In kinvey's documentation, they clearly stated that: 在kinvey的文档中,他们明确指出:

If the username does exist, the callback's onError method will be invoked 如果用户名确实存在,则将调用回调的onError方法

So when you execute this code: 因此,当您执行以下代码时:

User user = await myClient.User().createAsync(myUserName, myPassword);

if the user already exists , you will receive the error message inside onError function as below. 如果用户已经存在 ,您将在onError函数中收到如下错误消息。

@Override
public void onError(String error) {
     // do something with the error
     // maybe log it and/or throw the error to UI
}

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

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