当前位置: 首页>>代码示例>>C#>>正文


C# Tasks.TaskCompletionSource类代码示例

本文整理汇总了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));
 }
开发者ID:Balharmander123,项目名称:Rx.NET,代码行数:7,代码来源:TaskObservableExtensionsTest.cs

示例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;
        }
开发者ID:noex,项目名称:RSSDP,代码行数:34,代码来源:MulticastUdpSocket.cs

示例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));
        }
开发者ID:Ziriax,项目名称:Rx.NET,代码行数:13,代码来源:TaskObservableExtensionsTest.cs

示例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&lt;IEnumerable&lt;Receipt&gt; &gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:21,代码来源:BuddyTaskWrappers.cs

示例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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:21,代码来源:Sound.cs

示例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&lt;Boolean&gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:27,代码来源:BuddyTaskWrappers.cs

示例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&lt;IEnumerable&lt;Receipt&gt; &gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:21,代码来源:BuddyTaskWrappers.cs

示例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;
			}
		}
开发者ID:Yortw,项目名称:Yort.Ntp,代码行数:19,代码来源:WinRT_NtpTests.cs

示例9: RemoveAsync

 /// <summary>
 /// Remove an identity value for this user.
 /// </summary>
 /// <param name="value">The value to remove.</param>
 /// <returns>A Task&lt;Boolean&gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:21,代码来源:BuddyTaskWrappers.cs

示例10: GetAllAsync

 /// <summary>
 /// Returns all the identity values for this user.
 /// </summary>
 /// <returns>A Task&lt;IEnumerable&lt;IdentityItem&gt; &gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:20,代码来源:BuddyTaskWrappers.cs

示例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&lt;IEnumerable&lt;Message&gt; &gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:21,代码来源:BuddyTaskWrappers.cs

示例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&lt;Boolean&gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:23,代码来源:BuddyTaskWrappers.cs

示例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&lt;Boolean&gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:22,代码来源:BuddyTaskWrappers.cs

示例14: DeleteAsync

 /// <summary>
 /// Delete this message group.
 /// </summary>
 /// <returns>A Task&lt;Boolean&gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:20,代码来源:BuddyTaskWrappers.cs

示例15: GetFreeStoreItemsAsync

 /// <summary>
 /// Returns information about all items in the store for the current application which are marked as free.
 /// </summary>
 /// <returns>A Task&lt;IEnumerable&lt;StoreItem&gt; &gt;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;
 }
开发者ID:rajeshwarn,项目名称:Buddy-DotNet-SDK,代码行数:20,代码来源:BuddyTaskWrappers.cs


注:本文中的System.Threading.Tasks.System.Threading.Tasks.TaskCompletionSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。