Dofan February 2016

Why does this simple C# UWP Win2D program occasionally fail to render an image

Hi, my first post so please be gentle :)

I have written this simple C# UWP Win2D program that on occasions randomly fails to render the image on screen. The program runs without problems roughly 90% of the time, and as it should, it renders the image, oddly though every now and then it fails to render it.

When it fails, it still clears the canvas to the correct colour but it does not render anything else. The program seems to be running properly but when I place a break point on either the draw method or the update method a break does not occur.

'Break all' does break the program but it informs me "Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code)"

I hope this explains the situation that I am currently facing, I have included the code that is causing this problem, hopefully someone more knowledgeable than me can help me find a remedy.

Here is my XAML code ...

<Page
    x:Class="TheGrid.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TheGrid"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
    mc:Ignorable="d" 
    Unloaded="Page_Unloaded">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <canvas:CanvasAnimatedControl 
            x:Name="canvas" 
            ClearColor="Bisque" Update="canvas_Update" Draw="canvas_Draw" CreateResources="canvas_CreateResources"
            />
    </Grid>
</Page>

And here is the C# code behind ...

public sealed partial class MainPage : Page
    {
        CanvasBitmap         

Answers


AchmadJP February 2016

I think the problem is in here

private void canvas_CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
    {
        args.TrackAsyncAction(Canvas_CreateResourcesAsync(sender).AsAsyncAction());
    }

When using async, my teacher told me to always use await and async function. Because this will cause problem.

Some reading source : https://msdn.microsoft.com/en-us/library/hh191443.aspx

Post Status

Asked in February 2016
Viewed 1,139 times
Voted 10
Answered 1 times

Search




Leave an answer