public static async Task WriteableBitmapToStorageFile(WriteableBitmap WB, string fileName) { try { Guid BitmapEncoderGuid = BitmapEncoder.JpegEncoderId; fileName += ".jpg"; StorageFolder videoThumbsFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("videoThumbs", CreationCollisionOption.OpenIfExists); var file = await videoThumbsFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoderGuid, stream); using (Stream pixelStream = WB.PixelBuffer.AsStream()) { byte[] pixels = new byte[pixelStream.Length]; await pixelStream.ReadAsync(pixels, 0, pixels.Length); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)WB.PixelWidth, (uint)WB.PixelHeight, 96.0, 96.0, pixels); await pixelStream.FlushAsync(); } await encoder.FlushAsync(); await stream.FlushAsync(); } } catch (Exception e) { LogHelper.Log("Failed to save the video thunbnail for videoId:" + fileName); LogHelper.Log(StringsHelper.ExceptionToString(e)); } }
static LogHelper() { Task.Run(() => InitBackendFile()); Task.Run(() => InitFrontendFile()); TaskScheduler.UnobservedTaskException += (sender, args) => { args.SetObserved(); ApplicationSettingsHelper.SaveSettingsValue("LastUnhandledException", StringsHelper.ExceptionToString(args.Exception)); var lines = new List <string>(2) { "Unobserved Task Exception:", args.Exception.ToString() }; Task.Run(() => FrontendSemaphore(() => WriteInLog(_frontendLogFile, lines))); }; App.Current.UnhandledException += (o, ex) => { ApplicationSettingsHelper.SaveSettingsValue("LastUnhandledException", StringsHelper.ExceptionToString(ex.Exception)); var lines = new List <string>(2) { "Unhandled Exception:", ex.Exception.ToString() }; Task.Run(() => FrontendSemaphore(() => WriteInLog(_frontendLogFile, lines))); }; }