private void SaveTexture(Texture texture, string filename) { using (var image = texture.GetDataAsImage()) { //Send to server and store to disk var imageData = new TestResultImage { CurrentVersion = "1.0", Frame = "0", Image = image, TestName = "" }; var payload = new ScreenShotPayload { FileName = filename }; var resultFileStream = new MemoryStream(); var writer = new BinaryWriter(resultFileStream); imageData.Write(writer); Task.Run(() => { payload.Data = resultFileStream.ToArray(); payload.Size = payload.Data.Length; socketMessageLayer.Send(payload).Wait(); resultFileStream.Dispose(); }); } }