void context_DeviceReset(object sender, DeviceResetEventArgs e)
 {
 }
        private async void context_DeviceReset(object sender, DeviceResetEventArgs e)
        {
            this.ReleaseResources();

            string assetsPath = Package.Current.InstalledLocation.Path + "/Assets/Render/";

            byte[] vertexShaderByteCode = NativeFile.ReadAllBytes(assetsPath + "MiniCubeTexture_VS.fxo");
            this.vertexShader = new VertexShader(this.parentContext.D3DDevice, vertexShaderByteCode);

            byte[] pixelShaderByteCode = NativeFile.ReadAllBytes(assetsPath + "MiniCubeTexture_PS.fxo");
            this.pixelShader = new PixelShader(this.parentContext.D3DDevice, pixelShaderByteCode);

            this.vertexLayout = new InputLayout(this.parentContext.D3DDevice, vertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 16, 0)
            });

            SharpDX.Direct3D11.Buffer vertices = SharpDX.Direct3D11.Buffer.Create(this.parentContext.D3DDevice, BindFlags.VertexBuffer, new[]
            {
                -0.5f, -0.5f, -0.5f, 0.5f,     0.0f, 1.0f,
                -0.5f,  0.5f, -0.5f, 0.5f,     0.0f, 0.0f,
                0.5f,  0.5f, -0.5f, 0.5f,     1.0f, 0.0f,
                -0.5f, -0.5f, -0.5f, 0.5f,     0.0f, 1.0f,
                0.5f,  0.5f, -0.5f, 0.5f,     1.0f, 0.0f,
                0.5f, -0.5f, -0.5f, 0.5f,     1.0f, 1.0f,
            });

            this.vertexBufferBinding = new VertexBufferBinding(vertices, sizeof(float) * 6, 0);

            this.constantBuffer = new SharpDX.Direct3D11.Buffer(this.parentContext.D3DDevice, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            this.sampler = new SamplerState(this.parentContext.D3DDevice, new SamplerStateDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy = 16,
                MipLodBias = 0,
                MinimumLod = -float.MaxValue,
                MaximumLod = float.MaxValue
            });

#if SILVERLIGHT
            Deployment.Current.Dispatcher.BeginInvoke(() =>
#else
            await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
#endif

            {
                using (MemoryStream sourceStream = new MemoryStream(NativeFile.ReadAllBytes(assetsPath + "sharpdx.png")))
                {
#if SILVERLIGHT
                    BitmapImage image = new BitmapImage();
                    image.CreateOptions = BitmapCreateOptions.None;
                    image.SetSource(sourceStream);

                    WriteableBitmap bitmap = new WriteableBitmap(image);

                    using (DataStream dataStream = new DataStream(bitmap.Pixels.Length * 4, true, true))
                    {
                        dataStream.WriteRange<int>(bitmap.Pixels);
#else
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceStream.AsRandomAccessStream());
                    BitmapFrame bitmap = await decoder.GetFrameAsync(0);
                    PixelDataProvider dataProvider = await bitmap.GetPixelDataAsync(BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Premultiplied,
                        new BitmapTransform(),
                        ExifOrientationMode.IgnoreExifOrientation,
                        ColorManagementMode.DoNotColorManage);
                    byte[] pixelData = dataProvider.DetachPixelData();

                    using (DataStream dataStream = new DataStream(pixelData.Length, true, true))
                    {
                        dataStream.WriteRange<byte>(pixelData);
#endif

                        dataStream.Seek(0, SeekOrigin.Begin);

                        DataRectangle dataRectangle = new DataRectangle(dataStream.DataPointer, (int)(bitmap.PixelWidth * 4));

                        this.texture = new Texture2D(this.parentContext.D3DDevice, new Texture2DDescription()
                        {
                            Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                            Width = (int)bitmap.PixelWidth,
                            Height = (int)bitmap.PixelHeight,
                            ArraySize = 1,
                            MipLevels = 1,
                            BindFlags = BindFlags.ShaderResource,
                            Usage = ResourceUsage.Default,
                            CpuAccessFlags = CpuAccessFlags.None,
                            OptionFlags = ResourceOptionFlags.None,
                            SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0)
                        }, dataRectangle);

                        this.textureView = new ShaderResourceView(this.parentContext.D3DDevice, this.texture);
                    }

#if SILVERLIGHT
                    bitmap = null;
                    image = null;
#else
                    pixelData = null;
                    dataProvider = null;
                    bitmap = null;
                    decoder = null;
#endif
                }
            });
        }