本文整理汇总了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();
}
示例2: AsyncMethodWithViewModel
private async void AsyncMethodWithViewModel(IAsyncOperation<bool> asyncOperation, bool result, IViewModel viewModel)
{
bool b = await asyncOperation;
b.ShouldEqual(result);
ViewModel = viewModel;
AsyncMethodInvoked = true;
}
示例3: ExecuteFile
protected void ExecuteFile (IAsyncOperation op)
{
// if (op.Success)
// ProfilingOperations.Profile (profiler, doc);
//if (op.Success)
// doc.Run ();
}
示例4: AddOperation
public void AddOperation(IAsyncOperation operation)
{
lock (list) {
if (monitor.IsCancelRequested)
operation.Cancel ();
else
list.Add (operation);
}
}
示例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);
}
示例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);
});
}
}
示例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);
}
示例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;
};
}
}
示例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;
}
示例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);
}
示例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;
});
}
示例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.
}
}
示例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;
}
}
示例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;
}
示例15: ImageLoader
public ImageLoader (string url)
{
loadMonitor = new NullProgressMonitor ();
loadOperation = loadMonitor.AsyncOperation;
this.url = url;
Load ();
}