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


C# IAsyncOperation类代码示例

本文整理汇总了C#中IAsyncOperation的典型用法代码示例。如果您正苦于以下问题:C# IAsyncOperation类的具体用法?C# IAsyncOperation怎么用?C# IAsyncOperation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: AsyncOperationBitmapProvider

 public AsyncOperationBitmapProvider(IAsyncOperation<Bitmap> bitmapAsyncOperation)
 {
     m_bitmapAsyncOperation = bitmapAsyncOperation
         .AsTask()
         .ContinueWith(t => (IReadableBitmap)t.Result, TaskContinuationOptions.OnlyOnRanToCompletion|TaskContinuationOptions.ExecuteSynchronously)
         .AsAsyncOperation();
 }
开发者ID:modulexcite,项目名称:Lumia-imaging-sdk,代码行数:7,代码来源:BitmapExtensions.cs

示例2: AsyncMethodWithViewModel

 private async void AsyncMethodWithViewModel(IAsyncOperation<bool> asyncOperation, bool result, IViewModel viewModel)
 {
     bool b = await asyncOperation;
     b.ShouldEqual(result);
     ViewModel = viewModel;
     AsyncMethodInvoked = true;
 }
开发者ID:MuffPotter,项目名称:MugenMvvmToolkit,代码行数:7,代码来源:SerializableAsyncOperationTest.cs

示例3: ExecuteFile

		protected void ExecuteFile (IAsyncOperation op)
		{
//			if (op.Success)
//				ProfilingOperations.Profile (profiler, doc);

			//if (op.Success)
			//	doc.Run ();
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:8,代码来源:ProjectCommands.cs

示例4: AddOperation

 public void AddOperation(IAsyncOperation operation)
 {
     lock (list) {
         if (monitor.IsCancelRequested)
             operation.Cancel ();
         else
             list.Add (operation);
     }
 }
开发者ID:slluis,项目名称:monodevelop-prehistoric,代码行数:9,代码来源:AggregatedOperationMonitor.cs

示例5: OnMessageDialogShowAsyncCompleted

        void OnMessageDialogShowAsyncCompleted(IAsyncOperation<IUICommand> asyncInfo, AsyncStatus asyncStatus) {
            // Get the Color value
            IUICommand command = asyncInfo.GetResults();
            clr = (Color)command.Id;

            // Use a Dispatcher to run in the UI thread
            IAsyncAction asyncAction = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                OnDispatcherRunAsyncCallback);
        }
开发者ID:ronlemire2,项目名称:UWP-Testers,代码行数:9,代码来源:HowToAsync1Page.xaml.cs

示例6: GetConnectivityIntervalsAsyncHandler

        async private void GetConnectivityIntervalsAsyncHandler(IAsyncOperation<IReadOnlyList<ConnectivityInterval>> asyncInfo, AsyncStatus asyncStatus)
        {
            if (asyncStatus == AsyncStatus.Completed)
            {
                try
                {
                    String outputString = string.Empty;
                    IReadOnlyList<ConnectivityInterval> connectivityIntervals = asyncInfo.GetResults();

                    if (connectivityIntervals == null)
                    {
                        rootPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                rootPage.NotifyUser("The Start Time cannot be later than the End Time, or in the future", NotifyType.StatusMessage);
                            });
                        return;
                    }

                    // Get the NetworkUsage for each ConnectivityInterval
                    foreach (ConnectivityInterval connectivityInterval in connectivityIntervals)
                    {
                        outputString += PrintConnectivityInterval(connectivityInterval);

                        DateTimeOffset startTime = connectivityInterval.StartTime;
                        DateTimeOffset endTime = startTime + connectivityInterval.ConnectionDuration;
                        IReadOnlyList<NetworkUsage> networkUsages = await InternetConnectionProfile.GetNetworkUsageAsync(startTime, endTime, Granularity, NetworkUsageStates);

                        foreach (NetworkUsage networkUsage in networkUsages)
                        {
                            outputString += PrintNetworkUsage(networkUsage, startTime);
                            startTime += networkUsage.ConnectionDuration;
                        }
                    }

                    rootPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            rootPage.NotifyUser(outputString, NotifyType.StatusMessage);
                        });
                }
                catch (Exception ex)
                {
                    rootPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            rootPage.NotifyUser("An unexpected error occurred: " + ex.Message, NotifyType.ErrorMessage);
                        });
                }
            }
            else
            {
                rootPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        rootPage.NotifyUser("GetConnectivityIntervalsAsync failed with message:\n" + asyncInfo.ErrorCode.Message, NotifyType.ErrorMessage);
                    });
            }
        }
开发者ID:mbin,项目名称:Win81App,代码行数:55,代码来源:ProfileLocalUsageData.xaml.cs

示例7: OperCompleted

		void OperCompleted (IAsyncOperation op)
		{
			bool raiseEvent;
			lock (operations) {
				completed++;
				success = success && op.Success;
				successWithWarnings = success && op.SuccessWithWarnings;
				raiseEvent = (completed == operations.Count);
			}
			if (raiseEvent && Completed != null)
				Completed (this);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:12,代码来源:AggregatedAsyncOperation.cs

示例8: AppServiceConnectionCompleted

 void AppServiceConnectionCompleted(IAsyncOperation<AppServiceConnectionStatus> operation, AsyncStatus asyncStatus)
 {
     var status = operation.GetResults();
     if (status == AppServiceConnectionStatus.Success)
     {
         var secondOperation = _appServiceConnection.SendMessageAsync(null);
         secondOperation.Completed = (_, __) =>
         {
             _appServiceConnection.Dispose();
             _appServiceConnection = null;
         };
     }
 }
开发者ID:File-New-Project,项目名称:EarTrumpet,代码行数:13,代码来源:TrayIcon.cs

示例9: showPopup

        public async static Task<bool> showPopup(string message, bool errorServer = false)
        {
            // Close the previous one out
            if (messageDialogCommand != null)
            {
                messageDialogCommand.Cancel();
                messageDialogCommand = null;
            }

            MessageDialog dlg = new MessageDialog(message);

            if (errorServer)
            {
                dlg.Commands.Clear();
                dlg.Commands.Add(new UICommand("Retry"));
                dlg.Commands.Add(new UICommand("Cancel"));
            }

            messageDialogCommand = dlg.ShowAsync();
            var res = await messageDialogCommand;

            if (errorServer && res.Label == "Retry")
                return false;
            return true;
        }
开发者ID:speakproject,项目名称:windowsphone,代码行数:25,代码来源:MainPage.xaml.cs

示例10: OnButtonClick

        async void OnButtonClick(object sender, RoutedEventArgs e) {
            MessageDialog msgdlg = new MessageDialog("Choose a color", "How to Async #1");
            msgdlg.Commands.Add(new UICommand("Red", null, Colors.Red));
            msgdlg.Commands.Add(new UICommand("Green", null, Colors.Green));
            msgdlg.Commands.Add(new UICommand("Blue", null, Colors.Blue));

            // Start a five-second timer
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(5);
            timer.Tick += OnTimerTick;
            timer.Start();

            // Show the MessageDialog
            asyncOp = msgdlg.ShowAsync();
            IUICommand command = null;

            try {
                command = await asyncOp;
            }
            catch (Exception) {
                // The exception in this case will be TaskCanceledException
            }

            // Stop the timer
            timer.Stop();

            // If the operation was canceled, exit the method
            if (command == null) {
                return;
            }

            // Get the Color value and set the background brush
            Color clr = (Color)command.Id;
            contentGrid.Background = new SolidColorBrush(clr);
        }
开发者ID:ronlemire2,项目名称:UWP-Testers,代码行数:35,代码来源:HowToCancelAsyncPage.xaml.cs

示例11: Load

		void Load ()
		{
			var monitor = loadMonitor;
			System.Threading.ThreadPool.QueueUserWorkItem (delegate {
				try {
					HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create (url);
					WebResponse resp = req.GetResponse ();
					MemoryStream ms = new MemoryStream ();
					using (var s = resp.GetResponseStream ()) {
						s.CopyTo (ms);
					}
					var data = ms.ToArray ();

					MonoDevelop.Ide.DispatchService.GuiSyncDispatch (delegate {
						Gdk.PixbufLoader l = new Gdk.PixbufLoader (resp.ContentType);
						l.Write (data);
						image = l.Pixbuf;
						l.Close ();
						monitor.Dispose ();
					});
					
					// Replace the async operation to avoid holding references to all
					// objects that subscribed the Completed event.
					loadOperation = NullAsyncOperation.Success;
				} catch (Exception ex) {
					loadMonitor.ReportError (null, ex);
					Gtk.Application.Invoke (delegate {
						monitor.Dispose ();
					});
					loadOperation = NullAsyncOperation.Failure;
				}
				loadMonitor = null;
			});
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:34,代码来源:ImageLoader.cs

示例12: Show

        /// <summary>
        /// Shows the dialog. It takes <see cref="SystemDialogViewModel"/> to populate the system dialog. It also sets the first command to be 
        /// the default and last one to be the cancel command.
        /// </summary>
        /// <param name="viewType"> Type of dialog control. </param>
        public async void Show(Type viewType)
        {
            this.Initialize(); 

            var dialog = new MessageDialog(ViewModel.ActivationData.Message, ViewModel.ActivationData.Title);
            foreach (var command in ViewModel.ActivationData.Commands)
            {
                dialog.Commands.Add(new UICommand(command));
            }

            dialog.DefaultCommandIndex = 0;
            dialog.CancelCommandIndex = (uint)ViewModel.ActivationData.Commands.Length - 1;

            try
            {
                this.dialogTask = dialog.ShowAsync();
                var result = await this.dialogTask;

                this.dialogTask = null;
                this.NavigationService.GoBack(result.Label);
            }
            catch (TaskCanceledException ex)
            {
                // Happens when you call nanavigationSerivce.GoBack(...) while the dialog is still open.
            }
        }
开发者ID:bezysoftware,项目名称:MVVM-Dialogs,代码行数:31,代码来源:SystemDialogContainer.cs

示例13: Exception

        /// <summary>
        /// 语音识别
        /// </summary>
        /// <returns>识别文本</returns>
        public async Task<string> RecognizeAsync()
        {
            if (_initialization == null || _initialization.IsFaulted)
                _initialization = InitializeRecognizer(SpeechRecognizer.SystemSpeechLanguage);

            await _initialization;

            CancelRecognitionOperation();

            // Start recognition.
            try
            {
                _recognitionOperation = _speechRecognizer.RecognizeWithUIAsync();
                SpeechRecognitionResult speechRecognitionResult = await _recognitionOperation;
                // If successful, return the recognition result.
                if (speechRecognitionResult.Status == SpeechRecognitionResultStatus.Success)
                    return speechRecognitionResult.Text;
                else
                    throw new Exception($"Speech recognition failed. Status: {speechRecognitionResult.Status}");
            }
            catch (Exception ex) when ((uint)ex.HResult == HResultPrivacyStatementDeclined)
            {
                // Handle the speech privacy policy error.
                var messageDialog = new MessageDialog("您没有同意语音识别隐私声明,请同意后重试");
                await messageDialog.ShowAsync();
                throw;
            }
        }
开发者ID:GJian,项目名称:UWP-master,代码行数:32,代码来源:SpeechService.cs

示例14: NotSupportedException

        private static Task<int?> PlatformShow(string title, string description, List<string> buttons)
        {
            // TODO: MessageDialog only supports two buttons
            if (buttons.Count == 3)
                throw new NotSupportedException("This platform does not support three buttons");

            tcs = new TaskCompletionSource<int?>();

            MessageDialog dialog = new MessageDialog(description, title);
            foreach (string button in buttons)
                dialog.Commands.Add(new UICommand(button, null, dialog.Commands.Count));

            dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                async () =>
                {
                    try
                    {
                        // PlatformSetResult will cancel the task, resulting in an exception
                        dialogResult = dialog.ShowAsync();
                        var result = await dialogResult;
                        if (!tcs.Task.IsCompleted)
                            tcs.SetResult((int)result.Id);
                    }
                    catch (TaskCanceledException)
                    {
                        if (!tcs.Task.IsCompleted)
                            tcs.SetResult(null);
                    }
                });

            return tcs.Task;
        }
开发者ID:BrainSlugs83,项目名称:MonoGame,代码行数:32,代码来源:MessageBox.WinRT.cs

示例15: ImageLoader

		public ImageLoader (string url)
		{
			loadMonitor = new NullProgressMonitor ();
			loadOperation = loadMonitor.AsyncOperation;
			this.url = url;
			Load ();
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:7,代码来源:ImageLoader.cs


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