/// <summary> /// Convert HuaweiTask to System.Threading.Task with Generic return type /// </summary> /// <typeparam name="TResult">Return type,a Java object</typeparam> /// <param name="HuaweiTask">Huawei.Hmf.Tasks.Task class</param> /// <returns>System.Threading.Task with wrapped a generic type</returns> public static Task <TResult> CastTask <TResult>(this HuaweiTask HuaweiTask) where TResult : Java.Lang.Object { var tcs = new TaskCompletionSource <TResult>(); HuaweiTask.AddOnCompleteListener(new HuaweiTaskCompleteListener( t => { if (t.Exception == null) { tcs.TrySetResult(t.Result.JavaCast <TResult>()); } else { tcs.TrySetException(t.Exception); } })); return(tcs.Task); }
/// <summary> /// Convert HuaweiTask to System.Threading.Task without return type /// </summary> /// <param name="HuaweiTask">Huawei.Hmf.Tasks.Task</param> /// <returns>System.Threading.Task</returns> public static System.Threading.Tasks.Task CastTask(this HuaweiTask HuaweiTask) { var tcs = new TaskCompletionSource <bool>(); HuaweiTask.AddOnCompleteListener(new HuaweiTaskCompleteListener( t => { if (t.Exception == null) { tcs.TrySetResult(false); } else { tcs.TrySetException(t.Exception); } } )); return(tcs.Task); }
private void GetLastLocation() { Task lastLocation = fusedLocationProviderClient.LastLocation; lastLocation.AddOnSuccessListener(new LastLocationSuccess(this)).AddOnFailureListener(new LastLocationFailure(this)); }
public Java.Lang.Object Then(Huawei.Hmf.Tasks.Task task) { this.successAction(task); return(null); }
private void GetAAID() { Huawei.Hmf.Tasks.Task getAAID = instance.AAID; getAAID.AddOnSuccessListener(new GetAAIDSuccessListener()).AddOnFailureListener(new GetAAIDFailureListener()); }
public void OnComplete(HuaweiTask task) => OnCompleteHandler?.Invoke(task);