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


C# Tasks.TaskCompletionSource类代码示例

本文整理汇总了C#中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.TaskCompletionSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoginAsync

    public static System.Threading.Tasks.Task LoginAsync(string username, string password)
    {
        var tcs = new System.Threading.Tasks.TaskCompletionSource<PTPrincipal>();

        PTIdentity.GetPTIdentity(username, password, (o, e) =>
        {
            if (e.Error == null && e.Object != null)
            {
                SetPrincipal(e.Object);
                tcs.SetResult(null);
            }
            else
            {
                Logout();
                if (e.Error != null) 
                    tcs.SetException(e.Error.InnerException);
                else
                    tcs.SetCanceled();
            }
        });
        return tcs.Task;
    }
开发者ID:ChrisWay,项目名称:csla,代码行数:22,代码来源:PTPrincipal.cs

示例2: if

        global::System.Threading.Tasks.Task<object> global::Orleans.CodeGeneration.IGrainMethodInvoker.Invoke(global::Orleans.Runtime.IAddressable grain, int interfaceId, int methodId, object[] arguments)
        {

            try
            {                    if (grain == null) throw new System.ArgumentNullException("grain");
                switch (interfaceId)
                {
                    case 1895808213:  // ITransferTransaction
                        switch (methodId)
                        {
                            case 518927232: 
                                return ((ITransferTransaction)grain).Initialize((Guid)arguments[0], (Guid)arguments[1], (Decimal)arguments[2]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case 901321164: 
                                return ((ITransferTransaction)grain).ConfirmAccountValidatePassed().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case 1613436135: 
                                return ((ITransferTransaction)grain).ConfirmTransferOutPreparation().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case 108736162: 
                                return ((ITransferTransaction)grain).ConfirmTransferInPreparation().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case -1176500040: 
                                return ((ITransferTransaction)grain).ConfirmTransferOut().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case 1990501567: 
                                return ((ITransferTransaction)grain).ConfirmTransferIn().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case 751141822: 
                                return ((ITransferTransaction)grain).Cancel((TransactionFaileReason)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case -1251605435: 
                                return ((ITransferTransaction)grain).GetStatus().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case 1419660080: 
                                return ((ITransferTransaction)grain).GetTransferTransactionInfo().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }case -1097320095:  // IGrainWithGuidKey
                        switch (methodId)
                        {
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }
                    default:
                        throw new System.InvalidCastException("interfaceId="+interfaceId);
                }
            }
            catch(Exception ex)
            {
                var t = new System.Threading.Tasks.TaskCompletionSource<object>();
                t.SetException(ex);
                return t.Task;
            }
        }
开发者ID:jsonsugar,项目名称:Orleans.EventSourcing,代码行数:47,代码来源:orleans.codegen.cs

示例3: Delay

 /// <summary>
 /// Task.Delayが.NET 4だと搭載されていないので擬似関数作成
 /// </summary>
 /// <param name="milliseconds"></param>
 private void Delay(int milliseconds)
 {
     var tcs = new System.Threading.Tasks.TaskCompletionSource<object>();
     new System.Threading.Timer(_ => tcs.SetResult(null)).Change(milliseconds, -1);
     tcs.Task.Wait();
 }
开发者ID:BuminMacintosh,项目名称:FFXIV_Tools_WPF,代码行数:10,代码来源:TextTalker.cs

示例4: if

        global::System.Threading.Tasks.Task<object> global::Orleans.CodeGeneration.IGrainMethodInvoker.Invoke(global::Orleans.Runtime.IAddressable grain, int interfaceId, int methodId, object[] arguments)
        {

            try
            {{                    if (grain == null) throw new System.ArgumentNullException("grain");
                switch (interfaceId)
                {
                    case 1150057381:  // IPubSubManager
                        switch (methodId)
                        {
                            case -203526534: 
                                return ((IPubSubManager)grain).Register((IPubSubGrain)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case -2125469177: 
                                return ((IPubSubManager)grain).Unregister((IPubSubGrain)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }
                    default:
                        throw new System.InvalidCastException("interfaceId="+interfaceId);
                }
            }}
            catch(Exception ex)
            {{
                var t = new System.Threading.Tasks.TaskCompletionSource<object>();
                t.SetException(ex);
                return t.Task;
            }}
        }
开发者ID:tareq-s,项目名称:OrleansR,代码行数:28,代码来源:orleans.codegen.cs

示例5: if

        global::System.Threading.Tasks.Task<object> global::Orleans.CodeGeneration.IGrainMethodInvoker.Invoke(global::Orleans.Runtime.IAddressable grain, int interfaceId, int methodId, object[] arguments)
        {

            try
            {                    if (grain == null) throw new System.ArgumentNullException("grain");
                switch (interfaceId)
                {
                    case -627797884:  // IPerson
                        switch (methodId)
                        {
                            case -1544510960: 
                                return ((IPerson)grain).Register((PersonalAttributes)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case -516276551: 
                                return ((IPerson)grain).Marry((Guid)arguments[0], (String)arguments[1]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case 513673718: 
                                return ((IPerson)grain).GetFirstName().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case 160660420: 
                                return ((IPerson)grain).GetLastName().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case 1616597481: 
                                return ((IPerson)grain).GetIsMarried().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }case 1928988877:  // IGrainWithIntegerKey
                        switch (methodId)
                        {
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }
                    default:
                        throw new System.InvalidCastException("interfaceId="+interfaceId);
                }
            }
            catch(Exception ex)
            {
                var t = new System.Threading.Tasks.TaskCompletionSource<object>();
                t.SetException(ex);
                return t.Task;
            }
        }
开发者ID:SmartFire,项目名称:orleans.storageprovider.documentdb,代码行数:39,代码来源:orleans.codegen.cs

示例6: if

        global::System.Threading.Tasks.Task<object> global::Orleans.CodeGeneration.IGrainMethodInvoker.Invoke(global::Orleans.Runtime.IAddressable grain, int interfaceId, int methodId, object[] arguments)
        {

            try
            {                    if (grain == null) throw new System.ArgumentNullException("grain");
                switch (interfaceId)
                {
                    case -874440916:  // IChirperViewer
                        switch (methodId)
                        {
                            case -343496927: 
                                ((IChirperViewer)grain).NewChirpArrived((ChirperMessage)arguments[0]); return System.Threading.Tasks.Task.FromResult((object)true);
                            case 489541775: 
                                ((IChirperViewer)grain).SubscriptionAdded((ChirperUserInfo)arguments[0]); return System.Threading.Tasks.Task.FromResult((object)true);
                            case 1797324738: 
                                ((IChirperViewer)grain).SubscriptionRemoved((ChirperUserInfo)arguments[0]); return System.Threading.Tasks.Task.FromResult((object)true);
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }
                    default:
                        throw new System.InvalidCastException("interfaceId="+interfaceId);
                }
            }
            catch(Exception ex)
            {
                var t = new System.Threading.Tasks.TaskCompletionSource<object>();
                t.SetException(ex);
                return t.Task;
            }
        }
开发者ID:dVakulen,项目名称:JASN-vNext,代码行数:30,代码来源:orleans.codegen.cs

示例7: AddPictureWithWatermarkAsync

 /// <summary>
 /// Add a new picture to this album. Note that this method internally does two web-service calls, and the IAsyncResult object
 /// returned is only valid for the first one.
 /// </summary>
 /// <param name="photoStream">A stream containing the photo's contents..</param>
 /// <param name="comment">An optional comment for this picture.</param>
 /// <param name="latitude">An optional latitude for the picture.</param>
 /// <param name="longitude">An optional longitude for the picture.</param>
 /// <param name="appTag">An optional application tag.</param>
 /// <param name="watermarkmessage">An optional message to watermark the image with.</param>
 /// <returns>A Task&lt;Picture&gt;that can be used to monitor progress on this call.</returns>
 public System.Threading.Tasks.Task<Picture> AddPictureWithWatermarkAsync(Stream photoStream, string comment = "", double latitude = 0, double longitude = 0, string appTag = "", string watermarkmessage = "")
 {
     var tcs = new System.Threading.Tasks.TaskCompletionSource<Picture>();
     AddPictureWithWatermarkInternal(photoStream, comment, latitude, longitude, appTag, watermarkmessage, (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,代码来源:PhotoAlbum.cs

示例8: DeleteAsync

 /// <summary>
 /// Delete this photo album.
 /// </summary>
 /// <returns>A Task&lt;Boolean&gt;that can be used to monitor progress on this call.</returns>
 public System.Threading.Tasks.Task<Boolean> DeleteAsync()
 {
     var tcs = new System.Threading.Tasks.TaskCompletionSource<Boolean>();
     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,代码来源:PhotoAlbum.cs

示例9: if

        global::System.Threading.Tasks.Task<object> global::Orleans.CodeGeneration.IGrainMethodInvoker.Invoke(global::Orleans.Runtime.IAddressable grain, int interfaceId, int methodId, object[] arguments)
        {

            try
            {                    if (grain == null) throw new System.ArgumentNullException("grain");
                switch (interfaceId)
                {
                    case 1662910789:  // IDestination
                        switch (methodId)
                        {
                            case 1491328371: 
                                return ((IDestination)grain).Ping((IClient)arguments[0], (Message)arguments[1]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }case -1277021679:  // IGrainWithStringKey
                        switch (methodId)
                        {
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }
                    default:
                        throw new System.InvalidCastException("interfaceId="+interfaceId);
                }
            }
            catch(Exception ex)
            {
                var t = new System.Threading.Tasks.TaskCompletionSource<object>();
                t.SetException(ex);
                return t.Task;
            }
        }
开发者ID:dVakulen,项目名称:Orleans.PingPong,代码行数:31,代码来源:orleans.codegen.cs

示例10: if

        global::System.Threading.Tasks.Task<object> global::Orleans.CodeGeneration.IGrainMethodInvoker.Invoke(global::Orleans.Runtime.IAddressable grain, int interfaceId, int methodId, object[] arguments)
        {

            try
            {                    if (grain == null) throw new System.ArgumentNullException("grain");
                switch (interfaceId)
                {
                    case 1529258251:  // IPowerLine
                        switch (methodId)
                        {
                            case -1348462830: 
                                return ((IPowerLine)grain).SetPowerCurrent((Int32)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            case -449473587: 
                                return ((IPowerLine)grain).GetCurrentPower().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case 1042716812: 
                                return ((IPowerLine)grain).SubscribeForPowerNotifications((IPowerLineObserver)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }
                    default:
                        throw new System.InvalidCastException("interfaceId="+interfaceId);
                }
            }
            catch(Exception ex)
            {
                var t = new System.Threading.Tasks.TaskCompletionSource<object>();
                t.SetException(ex);
                return t.Task;
            }
        }
开发者ID:flyingoverclouds,项目名称:TD15FR-IotArchitectureHautePerformance,代码行数:30,代码来源:orleans.codegen.cs

示例11: if

        global::System.Threading.Tasks.Task<object> global::Orleans.CodeGeneration.IGrainMethodInvoker.Invoke(global::Orleans.Runtime.IAddressable grain, int interfaceId, int methodId, object[] arguments)
        {

            try
            {                    if (grain == null) throw new System.ArgumentNullException("grain");
                switch (interfaceId)
                {
                    case -2105953344:  // IDeviceGrain
                        switch (methodId)
                        {
                            case 1567424079: 
                                return ((IDeviceGrain)grain).GetColor().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case -1860597175: 
                                return ((IDeviceGrain)grain).SetColor((String)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)null; });
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }case -1277021679:  // IGrainWithStringKey
                        switch (methodId)
                        {
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }
                    default:
                        throw new System.InvalidCastException("interfaceId="+interfaceId);
                }
            }
            catch(Exception ex)
            {
                var t = new System.Threading.Tasks.TaskCompletionSource<object>();
                t.SetException(ex);
                return t.Task;
            }
        }
开发者ID:moonytheloony,项目名称:orleans,代码行数:33,代码来源:orleans.codegen.cs

示例12: if

        global::System.Threading.Tasks.Task<object> global::Orleans.CodeGeneration.IGrainMethodInvoker.Invoke(global::Orleans.Runtime.IAddressable grain, int interfaceId, int methodId, object[] arguments)
        {

            try
            {                    if (grain == null) throw new System.ArgumentNullException("grain");
                switch (interfaceId)
                {
                    case -1731488188:  // IMyGrainInterface
                        switch (methodId)
                        {
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }case -1277021679:  // IGrainWithStringKey
                        switch (methodId)
                        {
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }
                    default:
                        throw new System.InvalidCastException("interfaceId="+interfaceId);
                }
            }
            catch(Exception ex)
            {
                var t = new System.Threading.Tasks.TaskCompletionSource<object>();
                t.SetException(ex);
                return t.Task;
            }
        }
开发者ID:cdsalmons,项目名称:OrleansTemplates,代码行数:29,代码来源:orleans.codegen.cs

示例13: GetResponseAsync

 public System.Threading.Tasks.Task<IResponse> GetResponseAsync(System.Threading.CancellationToken cancellationToken)
 {
     System.Threading.Tasks.TaskCompletionSource<IResponse> tcs = new System.Threading.Tasks.TaskCompletionSource<IResponse>();
     tcs.SetResult(new ResponseImpl(xrequest.GetResponseAsync(cancellationToken)));
     return tcs.Task;
 }
开发者ID:patsy02,项目名称:KompetansetorgetXamarin,代码行数:6,代码来源:uauthimpl.cs

示例14: if

        global::System.Threading.Tasks.Task<object> global::Orleans.CodeGeneration.IGrainMethodInvoker.Invoke(global::Orleans.Runtime.IAddressable grain, int interfaceId, int methodId, object[] arguments)
        {

            try
            {                    if (grain == null) throw new System.ArgumentNullException("grain");
                switch (interfaceId)
                {
                    case 1700701008:  // ICalculatorActor
                        switch (methodId)
                        {
                            case 567326490: 
                                return ((ICalculatorActor)grain).Set((Decimal)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case 1818975443: 
                                return ((ICalculatorActor)grain).Add((Decimal)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case 1048698314: 
                                return ((ICalculatorActor)grain).Multiply((Decimal)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case -1887213722: 
                                return ((ICalculatorActor)grain).Divide((Decimal)arguments[0]).ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case 974166974: 
                                return ((ICalculatorActor)grain).Reset().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            case -940922787: 
                                return ((ICalculatorActor)grain).Get().ContinueWith(t => {if (t.Status == System.Threading.Tasks.TaskStatus.Faulted) throw t.Exception; return (object)t.Result; });
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }case -1097320095:  // IGrainWithGuidKey
                        switch (methodId)
                        {
                            default: 
                            throw new NotImplementedException("interfaceId="+interfaceId+",methodId="+methodId);
                        }
                    default:
                        throw new System.InvalidCastException("interfaceId="+interfaceId);
                }
            }
            catch(Exception ex)
            {
                var t = new System.Threading.Tasks.TaskCompletionSource<object>();
                t.SetException(ex);
                return t.Task;
            }
        }
开发者ID:Bee-Htcpcp,项目名称:OrleansEventJournal,代码行数:41,代码来源:orleans.codegen.cs

示例15: GetInitialUrlAsync

        public async override System.Threading.Tasks.Task<Uri> GetInitialUrlAsync()
        {
            // just return if no replacement requested
            if (string.IsNullOrEmpty(replacementUrlFormat))
                return await base.GetInitialUrlAsync();

            // get base class Uri
            System.Diagnostics.Debug.WriteLine("GetUriFromTaskUri: replacementUrlFormat:" + replacementUrlFormat);
            Uri uri = await base.GetInitialUrlAsync();
            System.Diagnostics.Debug.WriteLine("GetUriFromTaskUri: base.uri:" + uri);

            // need to extract state query string from base Uri because its scope isn't public.
            string baseUrl = uri.OriginalString;
            int stateIndex = baseUrl.LastIndexOf("&state=");
            string requestState = baseUrl.Substring(stateIndex + "&state=".Length);

            // verify that the base Url is same as our supposedly identical procedure. If not, there must be a code change in a new version of base class.
            string redoUrl = string.Format(
                             "{0}?client_id={1}&redirect_uri={2}&response_type={3}&scope={4}&state={5}",
                            AuthorizeUrl.AbsoluteUri,
                            Uri.EscapeDataString(ClientId),
                            Uri.EscapeDataString(RedirectUrl.AbsoluteUri),
                            AccessTokenUrl == null ? "token" : "code",
                            Uri.EscapeDataString(Scope),
                            Uri.EscapeDataString(requestState));
            if (baseUrl != redoUrl)
                throw new ArgumentException("GetInitialUrlAsync: Url comparison failure: base: " + baseUrl + " redo:" + redoUrl);

            // format replacement Uri
            uri = new Uri(string.Format(
                            replacementUrlFormat,
                            AuthorizeUrl.AbsoluteUri,
                            Uri.EscapeDataString(ClientId),
                            Uri.EscapeDataString(RedirectUrl.AbsoluteUri),
                            AccessTokenUrl == null ? "token" : "code",
                            Uri.EscapeDataString(Scope),
                            Uri.EscapeDataString(requestState)));
            System.Diagnostics.Debug.WriteLine("GetUriFromTaskUri: replacement uri:" + uri);

            System.Threading.Tasks.TaskCompletionSource<Uri> tcs = new System.Threading.Tasks.TaskCompletionSource<Uri>();
            tcs.SetResult(uri);
            return uri;
        }
开发者ID:patsy02,项目名称:KompetansetorgetXamarin,代码行数:43,代码来源:uauthimpl.cs


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