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


hi, first post please gentle :)

i have written simple c# uwp win2d program on occasions randomly fails render image on screen. program runs without problems 90% of time, , should, renders image, oddly though every , fails render it.

when fails, still clears canvas correct colour not render else. program seems running when place break point on either draw method or update method break not occur.

'break all' break program informs me "your app has entered break state, there no code show because threads executing external code (typically system or framework code)"

i hope explains situation facing, have included code causing problem, more knowledgeable me can me find remedy.

here 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 c# code behind ...

public sealed partial class mainpage : page     {         canvasbitmap bitmap1;          public mainpage()         {             this.initializecomponent();         }         private void canvas_createresources(canvasanimatedcontrol sender, canvascreateresourceseventargs args)         {             args.trackasyncaction(canvas_createresourcesasync(sender).asasyncaction());         }         async task canvas_createresourcesasync(canvasanimatedcontrol sender)         {             bitmap1 = await canvasbitmap.loadasync(sender, "assets/images/testimage.png");         }              private void canvas_update(icanvasanimatedcontrol sender, canvasanimatedupdateeventargs args)         {             // stuff         }         private void canvas_draw(icanvasanimatedcontrol sender, canvasanimateddraweventargs args)         {             args.drawingsession.drawimage(bitmap1, 256, 256);         }         private void page_unloaded(object sender, routedeventargs e)         {             this.canvas.removefromvisualtree();             this.canvas = null;         }     } 

thank in advance may able offer, please let me know if more information required.

edit 1.) have tried simplify problem removing

args.trackasyncaction(canvas_createresourcesasync(sender).asasyncaction());

and

async task canvas_createresourcesasync(canvasanimatedcontrol sender) { bitmap1 = await canvasbitmap.loadasync(sender, "assets/images/testimage.png"); }

and replacing

args.drawingsession.drawimage(bitmap1, 256, 256);

with

args.drawingsession.drawcircle(256, 256, 128, colors.black, 16);

this seems prevent problem occurring, can presume problem async pattern using.

i think problem in here

private void canvas_createresources(canvasanimatedcontrol sender, canvascreateresourceseventargs args)     {         args.trackasyncaction(canvas_createresourcesasync(sender).asasyncaction());     } 

when using async, teacher told me use await , async function. because cause problem.

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


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -