/
Easy Async for Windows Store Apps in Microsoft Visual C# an Easy Async for Windows Store Apps in Microsoft Visual C# an

Easy Async for Windows Store Apps in Microsoft Visual C# an - PowerPoint Presentation

tatiana-dople
tatiana-dople . @tatiana-dople
Follow
433 views
Uploaded On 2017-09-24

Easy Async for Windows Store Apps in Microsoft Visual C# an - PPT Presentation

Lucian Wischik Senior Program Manager Managed Languages DEVB317 Easy Async for Windows Store Apps in Microsoft Visual C and Microsoft Visual Basic Lucian Wischik Senior Program Manager Managed ID: 590423

task await data async await task async data processdata var future visual windows asynchronous progress basic downloaddata microsoft downloaddataasync

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Easy Async for Windows Store Apps in Mic..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Easy Async for Windows Store Apps in Microsoft Visual C# and Microsoft Visual Basic

Lucian WischikSenior Program ManagerManaged Languages

DEV-B317Slide2

Easy Async for Windows Store Apps in Microsoft Visual C# and Microsoft Visual Basic

Lucian WischikSenior Program ManagerManaged Languages

DEV-B317

p

lease wait for the next slide

clicking won’t make it come any fasterSlide3

The Future is the Future

Responsiveness and scalabilityAsync is becoming the

norm

Futures: Modern

abstractions

Details: Different but

similar

.NET Async

Windows Runtime AsyncSlide4

Synchronous vs. Asynchronous

var

data =

DownloadData

(...);

ProcessData

(data);

var

future =

DownloadDataAsync

(...);

future.ContinueWith

(data =>

ProcessData

(data));

DownloadDataAsync

ProcessData

STOP

ProcessData

DownloadDataSlide5

Synchronous vs. Asynchronous

DownloadDataAsync

ProcessData

STOP

ProcessData

DownloadData

STOP

var

data =

DownloadData

(...);

ProcessData

(data);

var

future =

DownloadDataAsync

(...);

future.ContinueWith

(data =>

ProcessData

(data));Slide6

C# and Visual Basic let you

doasynchronous programming

without

callbacksSlide7

Demo

Using await with the Windows RuntimeSlide8

a

wait

makes the rest of your method a callbackSlide9

async

“makes your method asynchronous”lets you put awaits in itSlide10

Awaitables

Task

Task<

TResult

>

Returned from

asyncC# and Visual Basic APIsAlready running

await directlyCan

await multiple timesStore and await later

IAsyncAction

IAsyncOperation

<

TResult

>

Returned from

async

Windows Runtime APIsAlready runningawait directly

Can await multiple timesStore and await laterOr, AsTask and

await laterSlide11

Task-returning vs. void-returning

async Task

Foo

Async

(…);

Can be awaited

“Give back control”Delegate asynchronous workUse for helper methodsUse for library methods

async void

Foo_Click(…);Cannot be awaited“Fire and forget” Start separate independent flow

Use for event handlers

Use to override void methodsSlide12

Demo

Coordinating TasksSlide13

Task

lets you coordinate activitiesSlide14

Task helpers

Yielding control

await

Task.Delay

(5000);

await

Task.Yield();Background running

var

result = await Task.Run(() => { … work … });

Parallel composition

var

winningTask

= await

Task.WhenAny(task1, task2); var

results = await Task.WhenAll(task1, task2);Slide15

Demo

CancellationSlide16

Cancellation and Progress

Pass CancellationToken

to

send

cancellation

Pass

IProgress to receive progress updatesawait FooAsync(…, cancel, progress);

await

FooAsync(…).AsTask(cancel, progress

);Slide17

Windows 8 has taken a big bet on asynchronous APIsSlide18

The await keyword

makes consuming async APIs simpleSlide19

No more callbacks!