private void OnConnected(IAsyncAction asyncinfo, AsyncStatus asyncstatus) { lock (this.syncer) { if (asyncinfo.AsTask().IsCompleted&& !asyncinfo.AsTask().IsFaulted&& this.sock != null && this.sock.Information.RemoteAddress != null) { this.PingBytes[this.PingBytes.Length - 1] = this.PingId; DataWriter writer; writer = new DataWriter(this.sock.OutputStream); writer.WriteBytes(this.PingBytes); DataWriterStoreOperation res = writer.StoreAsync(); res.AsTask().Wait(100); this.PingBytes[this.PingBytes.Length - 1] = (byte)(this.PingId + 1); // this buffer is re-used for the result/receive. invalidate the result now. writer.DetachStream(); writer.Dispose(); } else { this.sock = null; // will cause Done() to return true but this.Successful defines if the roundtrip completed } } }
internal static ConfiguredTaskAwaitable AsAwaitable( this IAsyncAction asyncAction, CancellationToken cancellationToken ) { return(asyncAction.AsTask(cancellationToken).ConfigureAwait(false)); }
public async void Connect() { #if NETFX_CORE Client = new StreamSocket(); #else Client = new TcpClient(Host, Port); #endif do { try { #if NETFX_CORE TokenSource = new CancellationTokenSource(Timeout); IAsyncAction action = Client.ConnectAsync(new HostName(Host), Port.ToString()); await action.AsTask(TokenSource.Token); #else #endif PostConnect(); BeginRead(); break; } catch (Exception e) { if (Persistent == false) { UDebug.LogException(e); Close(); } } } while (Persistent); }
public void CSCAUnzipped(string message) { IAsyncAction act = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { AddMessageToList("File unzipped to: " + message); }); Task t = act.AsTask(); }
public void Join() { #if NETFX_CORE _asyncAction.AsTask().Wait(); #else _thread.Join(); #endif }
public void DocChecksPerformed() { IAsyncAction act = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { AddMessageToList("Document checked electronically"); }); Task t = act.AsTask(); }
public void ErrorRaised(string err) { IAsyncAction act = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { AddMessageToList("Error during RFID" + Environment.NewLine + err); }); Task t = act.AsTask(); }
public void SessionOpened() { IAsyncAction act = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { AddMessageToList("RFID session opened"); }); Task t = act.AsTask(); }
public void CSCADownloaded(string messages) { IAsyncAction act = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { AddMessageToList("File downloaded as: " + messages); }); Task t = act.AsTask(); }
private static void Delete(StorageFile file) { if (file != null) { IAsyncAction asyncAction = file.DeleteAsync(); asyncAction.AsTask().Wait(); asyncAction.GetResults(); } }
//Send socket message to AmbiPro async Task SocketSendAmbiPro(string RemoteData) { try { //Check if not sending a socket already if (!vSendingSocketMsg) { //Check if server ip adres is valid string ServerIp = Convert.ToString(vApplicationSettings["ServerIp"]); string ServerPort = Convert.ToString(vApplicationSettings["ServerPortAmbiPro"]); if (!await ValidateRemoteIpAdres(ServerIp)) { return; } //Set the remote socket variables vSendingSocketMsg = true; //Update the status user interface txt_AppStatusDesc.Text = "Sending remote command..."; app_StatusBar.Visibility = Visibility.Visible; using (StreamSocket StreamSocket = new StreamSocket()) { using (CancellationTokenSource CancelToken = new CancellationTokenSource()) { CancelToken.CancelAfter(2500); IAsyncAction SocketConnectAsync = StreamSocket.ConnectAsync(new HostName(ServerIp), ServerPort); await SocketConnectAsync.AsTask(CancelToken.Token); } using (DataWriter DataWriter = new DataWriter(StreamSocket.OutputStream)) { DataWriter.WriteString(RemoteData); await DataWriter.StoreAsync(); } } vSendingSocketMsg = false; app_StatusBar.Visibility = Visibility.Collapsed; txt_ErrorConnect.Visibility = Visibility.Collapsed; txt_ErrorConnect2.Visibility = Visibility.Collapsed; } } catch { vSendingSocketMsg = false; app_StatusBar.Visibility = Visibility.Collapsed; if (!AVFunctions.DevMobile()) { txt_ErrorConnect.Visibility = Visibility.Visible; txt_ErrorConnect2.Visibility = Visibility.Visible; } await new MessageDialog("Failed to connect to the AmbiPro application on your PC please check this app settings, your network connection and make sure that AmbiPro is running on the target PC.", App.vApplicationName).ShowAsync(); } }
public static Task Run(RGSSEntry entry) { if (state != EngineState.Runing) { EntryCallback = entry; IAsyncAction asyncAction = ThreadPool.RunAsync(Worker, WorkItemPriority.High); return(asyncAction.AsTask()); } return(null); }
public static void Sync(this IAsyncAction oper) { var task = oper.AsTask(); if (task.Status == TaskStatus.Created) { task.Start(); } task.Wait(); }
public void Join() { #if !NETFX_CORE m_thread.Join(); #else if (m_workItem != null) { m_workItem.AsTask().Wait(); } #endif }
public static void Await(this IAsyncAction operation) { try { var task = operation.AsTask(); task.Wait(); } catch (AggregateException exception) { throw exception.InnerException; } }
private static async Task TranslateWinRTTaskCore(IAsyncAction operation, string filePath, bool isDirectory) { try { await operation.AsTask().ConfigureAwait(false); } catch (Exception exception) { throw TranslateWinRTException(exception, filePath, isDirectory); } }
public static void Await(this IAsyncAction operation) { var task = operation.AsTask(); task.Wait(); if (task.Exception != null) { // TODO - is this correct? throw task.Exception.InnerException; } }
public void MrzFromChipTaken(string mrz) { IAsyncAction act = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { AddMessageToList("MRZ taken"); tbxMrz.Text = mrz; Items.SelectedIndex = 1; }); Task t = act.AsTask(); }
void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args) { mainDeviceResources.InitMessage(); IAsyncAction pendingDrawTask = null; switch (CurrentOutput) { case OutputMode.CanvasControl: DrawToOutput(mainDeviceResources, args.DrawingSession); break; case OutputMode.CanvasImageBrush: DrawViaImageBrush(args.DrawingSession); break; case OutputMode.CanvasImageSource: pendingDrawTask = RunOnUIThread(DrawToImageSource); break; case OutputMode.CanvasSwapChain: DrawToSwapChain(); break; case OutputMode.CanvasVirtualControl: pendingDrawTask = RunOnUIThread(DrawToVirtualControl); break; case OutputMode.CanvasVirtualImageSource: pendingDrawTask = RunOnUIThread(DrawToVirtualImageSource); break; } // Show or hide overlay controls to fit the current mode. imageControl.Visibility = (CurrentOutput == OutputMode.CanvasImageSource) ? Visibility.Visible : Visibility.Collapsed; swapChainPanel.Visibility = (CurrentOutput == OutputMode.CanvasSwapChain) ? Visibility.Visible : Visibility.Collapsed; virtualControl.Visibility = (CurrentOutput == OutputMode.CanvasVirtualControl) ? Visibility.Visible : Visibility.Collapsed; virtualImageControl.Visibility = (CurrentOutput == OutputMode.CanvasVirtualImageSource) ? Visibility.Visible : Visibility.Collapsed; animatedControl.Visibility = (CurrentOutput == OutputMode.CanvasAnimatedControl) ? Visibility.Visible : Visibility.Collapsed; animatedControl.Paused = (CurrentOutput != OutputMode.CanvasAnimatedControl); // Update the info text. DispatchedHandler updateText = () => textBlock.Text = mainDeviceResources.GetFinalMessage(); if (pendingDrawTask == null) { updateText(); } else { pendingDrawTask.AsTask().ContinueWith(task => RunOnUIThread(updateText)); } }
public void SessionFinished(string messages) { IAsyncAction act = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { AddMessageToList(messages); if (!messages.Contains("error")) { Items.SelectedIndex = 1; } }); Task t = act.AsTask(); }
public static void Await(this IAsyncAction operation) { try { var task = operation.AsTask(); task.Wait(); } catch (AggregateException exception) { // this possibly oversimplifies the problem report throw exception.InnerException; } }
public async void ImageFromChipTaken(byte[] img) { if (img != null && img.Length >= 1) { IAsyncAction act = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { AddMessageToList("Face image taken"); }); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { BitmapImage BI = await BytesToBitmapImage(img); imgFace.Source = BI; }); Task t = act.AsTask(); } }
public SocketFrameHandler(AmqpTcpEndpoint endpoint, Func <StreamSocket> socketFactory, int connectionTimeout, int _readTimeout, int _writeTimeout) { Endpoint = endpoint; m_socket = socketFactory(); Connect(m_socket, endpoint, connectionTimeout); if (endpoint.Ssl.Enabled) { IAsyncAction ar = null; try { var cts = new CancellationTokenSource(); if (this.defaultTimeout.HasValue) { cts.CancelAfter(this.defaultTimeout.Value); } ar = this.m_socket.UpgradeToSslAsync( SocketProtectionLevel.Ssl, new HostName(endpoint.Ssl.ServerName)); ar.AsTask(cts.Token).Wait(); ar.GetResults(); } catch (Exception) { Close(); throw; } finally { if (ar != null) { ar.Close(); } } } m_reader = new NetworkBinaryReader(m_socket.InputStream.AsStreamForRead()); m_writer = new NetworkBinaryWriter(m_socket.OutputStream.AsStreamForWrite()); }
private void Connect(StreamSocket socket, AmqpTcpEndpoint endpoint, int timeout) { IAsyncAction ar = null; try { var cts = new CancellationTokenSource(); if (this.defaultTimeout.HasValue) { cts.CancelAfter(this.defaultTimeout.Value); } ar = socket.ConnectAsync(new HostName(endpoint.HostName), endpoint.Port.ToString(), SocketProtectionLevel.PlainSocket); if (!ar.AsTask(cts.Token).Wait(timeout)) { socket.Dispose(); throw new TimeoutException("Connection to " + endpoint + " timed out"); } ar.GetResults(); } catch (ArgumentException e) { throw new ConnectFailureException("Connection failed", e); } catch (Exception e) { // If this is an unknown status it means that the error is fatal and retry will likely fail. if (SocketError.GetStatus(e.HResult) == SocketErrorStatus.Unknown) { throw; } throw new ConnectFailureException("Connection failed", e); } finally { if (ar != null) { ar.Close(); } } }
} // end of Delete() /// <summary> /// Delete a file. Assumes userSpace. /// </summary> /// <param name="file"></param> /// <returns>true if successful</returns> public static bool Delete(StorageFile file) { bool result = false; if (file != null) { try { IAsyncAction action = file.DeleteAsync(); action.AsTask().ConfigureAwait(false); action.GetResults(); result = true; } catch { } } return(result); } // end of Delete()
private void OnConnected(IAsyncAction asyncinfo, AsyncStatus asyncstatus) { if (asyncinfo.AsTask().IsCompleted) { PingBytes[PingBytes.Length - 1] = PingId; DataWriter writer; writer = new DataWriter(sock.OutputStream); writer.WriteBytes(PingBytes); var res = writer.StoreAsync(); res.AsTask().Wait(100); writer.DetachStream(); writer.Dispose(); PingBytes[PingBytes.Length - 1] = (byte)(PingId - 1); } else { // TODO: handle error } }
public bool Connect(string host, string port) { try { _connectOperation = _clientSocket.ConnectAsync(new HostName(host), port); _connectOperation.AsTask().Wait(); if (_connectOperation.ErrorCode != null) { OnErrorOccured(new SocketErrorEventArgs(SocketErrorEventArgs.SocketMethod.Connect, SocketError.GetStatus(_connectOperation.ErrorCode.HResult).ToString())); _connectOperation = null; return(false); } _connectOperation = null; return(true); } catch (TaskCanceledException) { return(false); } catch (Exception ex) { OnErrorOccured(new SocketErrorEventArgs(SocketErrorEventArgs.SocketMethod.Connect, SocketError.GetStatus(ex.HResult).ToString())); ReCreateSocket(); return(false); } }
public static Task AsTask(object objAsyncAction) { IAsyncAction asyncAction = objAsyncAction as IAsyncAction; return(asyncAction.AsTask()); }
public static ConfiguredTaskAwaitable DontSync(this IAsyncAction self) { return(self.AsTask().ConfigureAwait(false)); }
internal static void WatchForError(this IAsyncAction self) => self.AsTask().WatchForError();