本文整理汇总了C#中System.Threading.Tasks.System.Threading.Tasks.TaskCompletionSource类的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Tasks.TaskCompletionSource类的具体用法?C# System.Threading.Tasks.TaskCompletionSource怎么用?C# System.Threading.Tasks.TaskCompletionSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Threading.Tasks.TaskCompletionSource类属于System.Threading.Tasks命名空间,在下文中一共展示了System.Threading.Tasks.TaskCompletionSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TaskToObservable_NonVoid_ArgumentChecking
public void TaskToObservable_NonVoid_ArgumentChecking()
{
ReactiveAssert.Throws<ArgumentNullException>(() => TaskObservableExtensions.ToObservable((System.Threading.Tasks.Task<int>)null));
var tcs = new System.Threading.Tasks.TaskCompletionSource<int>();
var task = tcs.Task;
ReactiveAssert.Throws<ArgumentNullException>(() => task.ToObservable().Subscribe(null));
}
示例2: ReceiveAsync
public Task<ReceivedUdpData> ReceiveAsync()
{
ThrowIfDisposed();
var taskCompletionSource = new System.Threading.Tasks.TaskCompletionSource<ReceivedUdpData>();
byte[] buffer = new byte[SsdpConstants.DefaultUdpSocketBufferSize];
_UdpClient.BeginReceiveFromGroup(buffer, 0, buffer.Length,
(asyncResult) =>
{
IPEndPoint receivedFromEndPoint;
_UdpClient.EndReceiveFromGroup(asyncResult, out receivedFromEndPoint);
var tcs = asyncResult.AsyncState as System.Threading.Tasks.TaskCompletionSource<ReceivedUdpData>;
var result = new ReceivedUdpData()
{
ReceivedFrom = new UdpEndPoint()
{
IPAddress = receivedFromEndPoint.Address.ToString(),
Port = receivedFromEndPoint.Port
},
Buffer = buffer,
ReceivedBytes = buffer.Length
};
tcs.SetResult(result);
},
taskCompletionSource
);
return taskCompletionSource.Task;
}
示例3: TaskToObservable_NonVoid_ArgumentChecking
public void TaskToObservable_NonVoid_ArgumentChecking()
{
var s = Scheduler.Immediate;
ReactiveAssert.Throws<ArgumentNullException>(() => TaskObservableExtensions.ToObservable((Task<int>)null));
ReactiveAssert.Throws<ArgumentNullException>(() => TaskObservableExtensions.ToObservable((Task<int>)null, s));
ReactiveAssert.Throws<ArgumentNullException>(() => TaskObservableExtensions.ToObservable(doneTask, default(IScheduler)));
var tcs = new System.Threading.Tasks.TaskCompletionSource<int>();
var task = tcs.Task;
ReactiveAssert.Throws<ArgumentNullException>(() => task.ToObservable().Subscribe(null));
}
示例4: GetReceiptsForUserAsync
/// <summary>
/// Finds the receipt list based on the FromDateTime parameter for the currently logged in user.
/// </summary>
/// <param name="fromDateTime">The starting date and time to get receipts from, leave this blank to get all the receipts.</param>
/// <returns>A Task<IEnumerable<Receipt> >that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<IEnumerable<Receipt>> GetReceiptsForUserAsync(this Buddy.Commerce commerce, System.Nullable<System.DateTime> fromDateTime = null)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<Receipt>>();
commerce.GetReceiptsForUserInternal(fromDateTime, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例5: GetSoundAsync
/// <summary>
/// Retrieves a sound from the Buddy sound library, and returns a Stream. Your application should perisist this stream locally in a location such as IsolatedStorage.
/// </summary>
/// <param name="soundName">The name of the sound file. See the Buddy Developer Portal "Sounds" page to find sounds and get their names.</param>
/// <param name="quality">The quality level of the file to retrieve.</param>
public Task<Stream> GetSoundAsync(string soundName, Buddy.Sounds.SoundQuality quality)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Stream>();
this.GetSoundInternal(soundName, quality, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例6: SaveReceiptAsync
/// <summary>
/// Saves a receipt for the purchase of an item made to the application's store.
/// </summary>
/// <param name="totalCost">The total cost for the items purchased in the transaction.</param>
/// <param name="totalQuantity">The total number of items purchased.</param>
/// <param name="storeItemID">The store ID of the item of the item being purchased.</param>
/// <param name="storeName">The name of the application's store to be saved with the transaction. This field is used by the commerce analytics to track purchases.</param>
/// <param name="receiptData">Optional information to store with the receipt such as notes about the transaction.</param>
/// <param name="customTransactionID">An optional app-specific ID to associate with the purchase.</param>
/// <param name="appData">Optional metadata to associate with the transaction.</param>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<Boolean> SaveReceiptAsync(this Buddy.Commerce commerce, string totalCost, int totalQuantity, int storeItemID, string storeName, string receiptData = "", string customTransactionID = "", string appData = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
commerce.SaveReceiptInternal(totalCost, totalQuantity, storeItemID, storeName, receiptData, customTransactionID, appData, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例7: GetReceiptForUserAndTransactionIDAsync
/// <summary>
/// Finds the receipt associated with the specified CustomTransactionID for the currently logged in user.
/// </summary>
/// <param name="customTransactionID">The CustomTransactionID of the transaction. For Facebook payments this is the OrderID of the transaction.</param>
/// <returns>A Task<IEnumerable<Receipt> >that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<IEnumerable<Receipt>> GetReceiptForUserAndTransactionIDAsync(this Buddy.Commerce commerce, string customTransactionID)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<Receipt>>();
commerce.GetReceiptForUserAndTransactionIDInternal(customTransactionID, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例8: WinRT_NtpClient_DefaultServer_GetsNonNullResponse
public async Task WinRT_NtpClient_DefaultServer_GetsNonNullResponse()
{
var ntpClient = new Yort.Ntp.NtpClient();
try
{
_GotTimeTaskCompletionSource = new TaskCompletionSource<DateTime?>();
ntpClient.TimeReceived += ntpClient_TimeReceived;
ntpClient.ErrorOccurred += NtpClient_ErrorOccurred;
ntpClient.BeginRequestTime();
var result = await _GotTimeTaskCompletionSource.Task;
Assert.AreNotEqual(null, result);
}
finally
{
ntpClient.TimeReceived -= ntpClient_TimeReceived;
}
}
示例9: RemoveAsync
/// <summary>
/// Remove an identity value for this user.
/// </summary>
/// <param name="value">The value to remove.</param>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<Boolean> RemoveAsync(this Buddy.Identity identity, string value)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
identity.RemoveInternal(value, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例10: GetAllAsync
/// <summary>
/// Returns all the identity values for this user.
/// </summary>
/// <returns>A Task<IEnumerable<IdentityItem> >that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<IEnumerable<IdentityItem>> GetAllAsync(this Buddy.Identity identity)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<IdentityItem>>();
identity.GetAllInternal((bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例11: GetSentAsync
/// <summary>
/// Get all sent message by the current user.
/// </summary>
/// <param name="afterDate">Optionally retreive only messages after a certain DateTime.</param>
/// <returns>A Task<IEnumerable<Message> >that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<IEnumerable<Message>> GetSentAsync(this Buddy.Messages messages, System.DateTime afterDate = default(DateTime))
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<Message>>();
messages.GetSentInternal(afterDate, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例12: UpdatePictureAsync
/// <summary>
/// Update virtual album picture comment or app.tag.
/// </summary>
/// <param name="picture">The picture to be updated, either PicturePublic or Picture works.</param>
/// <param name="newComment">The new comment to set for the picture.</param>
/// <param name="newAppTag">An optional new application tag for the picture.</param>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<Boolean> UpdatePictureAsync(this Buddy.VirtualAlbum virtualAlbum, Buddy.PicturePublic picture, string newComment, string newAppTag = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
virtualAlbum.UpdatePictureInternal(picture, newComment, newAppTag, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例13: AcceptAsync
/// <summary>
/// Accept a friend request from a user.
/// </summary>
/// <param name="user">The user to accept as friend. Can't be null and must be on the friend requests list.</param>
/// <param name="appTag">Tag this friend accept with a string.</param>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<Boolean> AcceptAsync(this Buddy.FriendRequests friendRequests, Buddy.User user, string appTag = "")
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
friendRequests.AcceptInternal(user, appTag, (bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例14: DeleteAsync
/// <summary>
/// Delete this message group.
/// </summary>
/// <returns>A Task<Boolean>that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<Boolean> DeleteAsync(this Buddy.MessageGroup messageGroup)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
messageGroup.DeleteInternal((bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}
示例15: GetFreeStoreItemsAsync
/// <summary>
/// Returns information about all items in the store for the current application which are marked as free.
/// </summary>
/// <returns>A Task<IEnumerable<StoreItem> >that can be used to monitor progress on this call.</returns>
public static System.Threading.Tasks.Task<IEnumerable<StoreItem>> GetFreeStoreItemsAsync(this Buddy.Commerce commerce)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<IEnumerable<StoreItem>>();
commerce.GetFreeStoreItemsInternal((bcr) =>
{
if (bcr.Error != BuddyServiceClient.BuddyError.None)
{
tcs.TrySetException(new BuddyServiceException(bcr.Error));
}
else
{
tcs.TrySetResult(bcr.Result);
}
});
return tcs.Task;
}