Windows Universal app tries to develop "51 microcontroller Assembly" second update summary

Source: Internet
Author: User

First, preface

Yesterday updated 10 days ago to the windows8.1 platform and WindowsPhone platform of general application "51 microcontroller assembly", always add live tile and the Groupstyle application of the ListView. Below is the main review of how to use background tasks to add live tiles

Second, live tile

Live tiles are also available a few days ago, and basic content can be viewed in my previous blog post about live tiles. Here I straighten out in my app, using Backgroudtask to dynamically update the tiles.

Step1: First add the Backgroutask component. One or two

Step2:

Refer the Backgroundtask to the Hubapp.windows and Hubapp.windowsphone directories, such as:

Step3: Rewriting backgrountask under the Hubappbackgroundtask class (the specific name can be changed), this is important, because the background is actually executed under this class to write

Add the interface Ibackgroundtask and implement the interface code as follows:

  Public Sealed classHubappbackgroundtask:ibackgroundtask {Private Static stringFILENAME ="Codecopyfile.xml";  Public Async voidRun (ibackgroundtaskinstance taskinstance) {backgroundtaskdeferral Deferral= Taskinstance.getdeferral ();//necessary for            Try//Specific background code execution            {                  varCode=awaitGetrandomcode ();//Data for Tiles                if(code!=NULL) {tilesetter.creattiles (code);//Update Tile                }            }            Catch(Exception) {Throw; }            finally{deferral.complete ();//necessary for            }        }}

The update tile Tilesetter.creattiles (code) method codes are as follows:
 Public Static voidcreattiles (Collectcode code) {stringTilesquare150x150image =@"Ms-appx:///assets/smalllogo.scale-240.png"; stringTilesquare310x150image =@"Ms-appx:///assets/widelogo.scale-240.png"; XmlDocument Tilexml=NewXmlDocument (); ////////////////////////////////////////////////////////            //Find all the available tile template formats at://      http://msdn.microsoft.com/en-us/library/windows/apps/Hh761491.aspx            stringTilestring ="<tile>"+"<visual version=\ "2\" >"+"<binding template=\ "tilesquare150x150peekimageandtext03\" fallback=\ "tilesquarepeekimageandtext03\" > "+"<image id=\ "1\" src=\ ""+ Tilesquare150x150image +"\ "alt=\" alt text\ "/>"+"<text id=\ "1\" >"+ code. Title +"</text>"+"<text id=\ "2\" >"+ code. Subtitle +"</text>"+"</binding>"+"<binding template=\ "tilewide310x150peekimage01\" fallback=\ "tilewidepeekimage01\" >"+"<image id=\ "1\" src=\ ""+ Tilesquare310x150image +"\ "alt=\" alt text\ "/>"+"<text id=\ "1\" >"+ code. Title +"</text>"+"<text id=\ "2\" >"+ code. Subtitle +"</text>"+"</binding>"+"</visual>"+"</tile>";            Tilexml.loadxml (tilestring); //New Tile NotificationTilenotification tile =Newtilenotification (Tilexml); //Update Tile NotificationsTileupdater Updatetiler =tileupdatemanager.createtileupdaterforapplication (); Updatetiler.enablenotificationqueue (false);            Updatetiler.clear ();        Updatetiler.update (tile); }    }... Public Sealed classCollectcode { PublicCollectcode (String uniqueId, string title, String subtitle,intcount) {             This. UniqueId =uniqueId;  This. Title =title;  This. Subtitle =subtitle;  This. Count =count; }         Public stringUniqueId {Get;Set; }  Public stringTitle {Get;Set; }  Public stringSubtitle {Get;Set; }  Public intCount {Get;Set; } }

So far backgroundtask is ready.

STEP3: Register the appropriate backgroundtask in the app

The first step is to declare a background task on the Package.appxmanifest list, such as:

Then register the background task on the app's code. In the 51 microcontroller assembly, I registered the background task in App.xaml.cs, C # code is as follows:

 protected Async Override voidOnLaunched (Launchactivatedeventargs e) {...//Make sure the current window is activeWindow.Current.Activate ();        Init (); } Private Async voidInit () {awaitBackgroundtaskhelper.register (); }....  Public Sealed classBackgroundtaskhelper {Static stringTaskName ="Backgroundtask"; Static stringTaskentrypoint ="Backgroundtask.hubappbackgroundtask";  Public Static Asynctask<BOOL> Register (Action action =NULL)        {            Try{UnRegister (); //Do the registeration//Check access permissionBackgroundaccessstatus status =awaitBackgroundexecutionmanager.requestaccessasync (); Switch(status) { CaseBackgroundaccessstatus.denied://reach Maxmium number, or, disabled by user                        return false;  Casebackgroundaccessstatus.unspecified:return false;  Casebackgroundaccessstatus.allowedmayuseactiverealtimeconnectivity: Break; }                //register the task in the next step.Backgroundtaskbuilder Builder =NewBackgroundtaskbuilder (); Builder. Name=TaskName; Builder. Taskentrypoint=Taskentrypoint; Builder. Settrigger (NewTimetrigger ( the,false));//run every minutes                varRegistration =Builder.                Register (); if(Registration! =NULL&& Action! =NULL) {registration.completed+ = (s, a) = ={action ();                }; }                return true; }            Catch            {                return false; }        }         Public Static BOOLUnRegister () {Try{backgroundtaskregistration Task=NULL; //Check for existing registrations of this background task.                foreach(varCurinchbackgroundtaskregistration.alltasks) {if(cur. Value.name = =taskname) {                        //The task is already registered.Task =( backgroundtaskregistration) (cur.                        Value);  Break; }                }                if(Task! =NULL) {task. Unregister (false); }                return true; }            Catch            {                return false; }        }    }

(This registered background task code, is to draw on the Bo Master @ms-uap http://www.cnblogs.com/ms-uap/application code-=-)

The app can now dynamically update its own tiles in the background.

Third, something

Yesterday update when logged on on Windows and the Development Center on the WindowsPhone saw the next 51 single-chip computer compilation download situation, also pretty good more than 1000 (for the real first development of the application I still very cool),

Unexpectedly, windows8.1 will have more than 700 downloads, it seems windows8.1 tablet users than WindowsPhone users also Doha.

Tomorrow will be the next Guangzhou back to school =-= the next semester refueling it! Junior in the spare time to develop a what let oneself learn????

Windows Universal app tries to develop "51 microcontroller Assembly" second update summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.