/// <summary> /// Resource management is not proper here. Suggest an improvement. /// </summary> /// <param name="file"></param> /// <returns></returns> private async Task SetSource(IStorageFile file) { var stream = await file.OpenReadAsync(); sourceStream = stream; await StoreUtil.OnUiThread(() => { Player.SetSource(stream, stream.ContentType); }); }
public async Task UpdateProgress() { await StoreUtil.OnUiThread(() => { OnPropertyChanged("Status"); OnPropertyChanged("BytesReceived"); OnPropertyChanged("TotalBytesToReceive"); OnPropertyChanged("TotalBytesToReceiveReadable"); }); //Debug.WriteLine(Progress.Status + ": " + Progress.BytesReceived + " / " + Progress.TotalBytesToReceive); }
private async void ws_MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args) { try { // throws Exception if eof is received, which is the case for example if auth fails var reader = args.GetDataReader(); var message = reader.ReadString(reader.UnconsumedBufferLength); await StoreUtil.OnUiThread(() => OnMessageReceived(message)); } catch (Exception) { // assumes eof has been received i.e. the server has closed the connection // http://msdn.microsoft.com/en-US/library/windows/apps/hh701366 ws.Close(1005, String.Empty); } }
// When operations happen on a background thread we have to marshal UI updates back to the UI thread. private void MarshalLog(string value) { StoreUtil.OnUiThread(() => Log(value)); }
public Task Pause() { return(StoreUtil.OnUiThread(Player.Pause)); }
public Task Play() { return(StoreUtil.OnUiThread(Player.Play)); }
public Task Stop() { return(StoreUtil.OnUiThread(Player.Stop)); }
private static Task OnUi(Task t) { return(StoreUtil.OnUiThread(async() => await t)); }
async void webSocket_MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args) { var reader = args.GetDataReader(); var msg = reader.ReadString(reader.UnconsumedBufferLength); await StoreUtil.OnUiThread(() => Output = msg); }
//public async Task TestWebSocketsWrapper() { // await ws.Connect(); // ws.Opened += () => SetOutput("Opened!"); // ws.MessageReceived += msg => SetOutput("Got msg: " + msg); // ws.Closed += reason => SetOutput("Closed. " + reason); // Output = "Connected."; // //await ws.Send(@"{""cmd"":""status""}"); // //Output = "Sent message"; //} private async void SetOutput(string msg) { await StoreUtil.OnUiThread(() => Output = msg); }