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


C# CancellationToken.GetValueOrDefault方法代码示例

本文整理汇总了C#中System.Threading.CancellationToken.GetValueOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# CancellationToken.GetValueOrDefault方法的具体用法?C# CancellationToken.GetValueOrDefault怎么用?C# CancellationToken.GetValueOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.CancellationToken的用法示例。


在下文中一共展示了CancellationToken.GetValueOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DiscoverPath

        private IEnumerable<PathElement> DiscoverPath(ChainedHeader fromBlock, ChainedHeader toBlock, Func<UInt256, ChainedHeader> getChainedHeader, CancellationToken? cancelToken)
        {
            // find height difference between chains
            var heightDelta = toBlock.Height - fromBlock.Height;

            var currentFromBlock = fromBlock;
            var currentToBlock = toBlock;

            while (currentFromBlock.Hash != currentToBlock.Hash)
            {
                // cooperative loop
                cancelToken.GetValueOrDefault(CancellationToken.None).ThrowIfCancellationRequested();

                // from chain is longer, rewind it
                if (currentFromBlock.Height > currentToBlock.Height)
                {
                    // if no further rollback is possible, chain mismatch
                    if (currentFromBlock.Height == 0)
                        throw new InvalidOperationException();

                    yield return new PathElement(PathChain.From, currentFromBlock);
                    currentFromBlock = getChainedHeader(currentFromBlock.PreviousBlockHash);
                }
                // to chain is longer, rewind it
                else if (currentToBlock.Height > currentFromBlock.Height)
                {
                    // if no further rollback is possible, chain mismatch
                    if (currentToBlock.Height == 0)
                        throw new InvalidOperationException();

                    yield return new PathElement(PathChain.To, currentToBlock);
                    currentToBlock = getChainedHeader(currentToBlock.PreviousBlockHash);
                }
                // chains are same height, rewind both
                else
                {
                    // if no further rollback is possible, chain mismatch
                    if (currentFromBlock.Height == 0 || currentToBlock.Height == 0)
                        throw new InvalidOperationException();

                    yield return new PathElement(PathChain.From, currentFromBlock);
                    yield return new PathElement(PathChain.To, currentToBlock);

                    currentFromBlock = getChainedHeader(currentFromBlock.PreviousBlockHash);
                    currentToBlock = getChainedHeader(currentToBlock.PreviousBlockHash);
                }
            }

            // return last common block
            yield return new PathElement(PathChain.LastCommon, currentFromBlock);
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:51,代码来源:BlockchainWalker.cs

示例2: Start

        public void Start(CancellationToken? cancellationToken)
        {
            var startLogMessage = new StringBuilder();
            startLogMessage.AppendFormat("Starting MessengerServer with {0} processes.", _maxProcessCount).AppendLine();
            startLogMessage.AppendFormat("  Batch size: {0}", _messageBatchSize).AppendLine();
            startLogMessage.AppendFormat("  Check interval: {0}", _checkInterval).AppendLine();
            startLogMessage.AppendFormat("  Archive messages: {0}", _completedMessages.Archive).AppendLine();
            startLogMessage.AppendFormat("  Cleanup old messages: {0}", _completedMessages.Cleanup).AppendLine();
            Logger.Info(startLogMessage.ToString());

            var token = cancellationToken.GetValueOrDefault(CancellationToken.None);
            Task.Factory.StartNew(() => StartMonitor(token), TaskCreationOptions.LongRunning);

            if (_completedMessages.Cleanup)
            {
                CleanupService cleanupService = new CleanupService(Logger, _repositoryFactory.Create());
                cleanupService.Start(_completedMessages.CleanOlderThanUtc, token);
            }
        }
开发者ID:mantasaudickas,项目名称:fat-queue,代码行数:19,代码来源:MessengerServer.cs

示例3: Sleep

 public static void Sleep(this TimeSpan timeToDelay, ILogger logger, CancellationToken? cancellationToken = null)
 {
     try
     {
         var token = cancellationToken.GetValueOrDefault(CancellationToken.None);
         if (!token.IsCancellationRequested)
         {
             Task task = Task.Delay(timeToDelay, token);
             task.Wait(token);
         }
     }
     catch (TaskCanceledException)
     {
     }
     catch (OperationCanceledException)
     {
     }
     catch (Exception e)
     {
         logger.Error(e.GetFormattedError("Sleep task failed!"));
     }
 }
开发者ID:mantasaudickas,项目名称:fat-queue,代码行数:22,代码来源:TaskExtensions.cs

示例4: ContractorGet

 public async Task<ContractorGet.response> ContractorGet(ContractorGet.request request, CancellationToken? token = null)
 {
     return await SendAsync<ContractorGet.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例5: CallbackCreate

 public async Task<CallbackCreate.response> CallbackCreate(CallbackCreate.request request, CancellationToken? token = null)
 {
     return await SendAsync<CallbackCreate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例6: TimeEntryUpdate

 public async Task<TimeEntryUpdate.response> TimeEntryUpdate(TimeEntryUpdate.request request, CancellationToken? token = null)
 {
     return await SendAsync<TimeEntryUpdate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例7: EstimateMarkAsSent

 public async Task<EstimateMarkAsSent.response> EstimateMarkAsSent(EstimateMarkAsSent.request request, CancellationToken? token = null)
 {
     return await SendAsync<EstimateMarkAsSent.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例8: PromptForInputsAsync

        public void PromptForInputsAsync(bool isReprompt, DateTimeOffset firstPromptTimestamp, IEnumerable<InputGroup> inputGroups, CancellationToken? cancellationToken, bool showCancelButton, string nextButtonText, string cancelConfirmation, string incompleteSubmissionConfirmation, string submitConfirmation, bool displayProgress, Action postDisplayCallback, Action<IEnumerable<InputGroup>> callback)
        {
            new Thread(() =>
                {
                    if (inputGroups == null || inputGroups.Count() == 0 || inputGroups.All(inputGroup => inputGroup == null))
                    {
                        callback(inputGroups);
                        return;
                    }

                    // only one prompt can run at a time...enforce that here.
                    lock (PROMPT_FOR_INPUTS_LOCKER)
                    {
                        if (PROMPT_FOR_INPUTS_RUNNING)
                        {
                            _logger.Log("A prompt is already running. Dropping current prompt request.", LoggingLevel.Normal, GetType());
                            callback(inputGroups);
                            return;
                        }
                        else
                            PROMPT_FOR_INPUTS_RUNNING = true;
                    }

                    bool firstPageDisplay = true;

                    Stack<int> inputGroupNumBackStack = new Stack<int>();

                    for (int inputGroupNum = 0; inputGroups != null && inputGroupNum < inputGroups.Count() && !cancellationToken.GetValueOrDefault().IsCancellationRequested; ++inputGroupNum)
                    {
                        InputGroup inputGroup = inputGroups.ElementAt(inputGroupNum);

                        ManualResetEvent responseWait = new ManualResetEvent(false);

                        // run voice inputs by themselves, and only if the input group contains exactly one voice input.
                        if (inputGroup.Inputs.Count == 1 && inputGroup.Inputs[0] is VoiceInput)
                        {
                            VoiceInput voiceInput = inputGroup.Inputs[0] as VoiceInput;

                            if (voiceInput.Enabled && voiceInput.Display)
                            {
                                voiceInput.RunAsync(isReprompt, firstPromptTimestamp, response =>
                                    {                
                                        responseWait.Set();
                                    });
                            }
                            else
                                responseWait.Set();
                        }
                        else
                        {
                            BringToForeground();

                            Device.BeginInvokeOnMainThread(async () =>
                                {
                                    PromptForInputsPage promptForInputsPage = new PromptForInputsPage(inputGroup, inputGroupNum + 1, inputGroups.Count(), showCancelButton, nextButtonText, cancellationToken, cancelConfirmation, incompleteSubmissionConfirmation, submitConfirmation, displayProgress, result =>
                                        {
                                            if (result == PromptForInputsPage.Result.Cancel || result == PromptForInputsPage.Result.NavigateBackward && inputGroupNumBackStack.Count == 0)
                                                inputGroups = null;
                                            else if (result == PromptForInputsPage.Result.NavigateBackward)
                                                inputGroupNum = inputGroupNumBackStack.Pop() - 1;
                                            else
                                                inputGroupNumBackStack.Push(inputGroupNum);

                                            responseWait.Set();
                                        });

                                    // do not display prompts page under the following conditions:  1) there are no inputs displayed on it. 2) the cancellation 
                                    // token has requested a cancellation. if any of these conditions are true, set the wait handle and continue to the next input group.

                                    if (promptForInputsPage.DisplayedInputCount == 0)
                                    {
                                        // if we're on the final input group and no inputs were shown, then we're at the end and we're ready to submit the 
                                        // users' responses. first check that the user is ready to submit. if the user isn't ready, move back to the previous 
                                        // input group if there is one.
                                        if (inputGroupNum >= inputGroups.Count() - 1 &&
                                            !string.IsNullOrWhiteSpace(submitConfirmation) &&
                                            inputGroupNumBackStack.Count > 0 &&
                                            !(await App.Current.MainPage.DisplayAlert("Confirm", submitConfirmation, "Yes", "No")))
                                        {
                                            inputGroupNum = inputGroupNumBackStack.Pop() - 1;
                                        }

                                        responseWait.Set();
                                    }
                                    else if (cancellationToken.GetValueOrDefault().IsCancellationRequested)
                                        responseWait.Set();
                                    else
                                    {
                                        await App.Current.MainPage.Navigation.PushModalAsync(promptForInputsPage, firstPageDisplay);  // only animate the display for the first page

                                        firstPageDisplay = false;

                                        if (postDisplayCallback != null)
                                            postDisplayCallback();
                                    }                                    
                                });
                        }

                        responseWait.WaitOne();    
                    }
//.........这里部分代码省略.........
开发者ID:shamik94,项目名称:sensus,代码行数:101,代码来源:SensusServiceHelper.cs

示例9: StaffDelete

 public async Task<StaffDelete.response> StaffDelete(StaffDelete.request request, CancellationToken? token = null)
 {
     return await SendAsync<StaffDelete.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例10: ReportGetProfitDetails

 public async Task<ReportGetProfitDetails.response> ReportGetProfitDetails(ReportGetProfitDetails.request request, CancellationToken? token = null)
 {
     return await SendAsync<ReportGetProfitDetails.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例11: RecurringList

 public async Task<RecurringList.response> RecurringList(RecurringList.request request, CancellationToken? token = null)
 {
     return await SendAsync<RecurringList.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例12: ReceiptGet

 public async Task<byte[]> ReceiptGet(ReceiptGet.request request, CancellationToken? token = null)
 {
     return await GetBytesAsync(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例13: InvoiceSendBySnailMail

 public async Task<InvoiceSendBySnailMail.response> InvoiceSendBySnailMail(InvoiceSendBySnailMail.request request, CancellationToken? token = null)
 {
     return await SendAsync<InvoiceSendBySnailMail.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例14: EstimateSendByEmail

 public async Task<byte[]> EstimateSendByEmail(EstimateSendByEmail.request request, CancellationToken? token = null)
 {
     return await GetBytesAsync(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs

示例15: SystemCurrent

 public async Task<SystemCurrent.response> SystemCurrent(SystemCurrent.request request, CancellationToken? token = null)
 {
     return await SendAsync<SystemCurrent.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }
开发者ID:mattjcowan,项目名称:FreshBooks.Api,代码行数:4,代码来源:FreshBooksClient.partial.cs


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