Build 2012 1/2/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Building Scalable Web Apps with Windows Azure Name Title Microsoft Corporation.
Parallel Performance Tools in Visual Studio 2010.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Reprint Outstanding Transactions Report © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Interactivity Navigating a data model Working with large quantities of data Entry Editing and adding data User feedback and validation Presentation.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
public static void PausePrintAsync() { ThreadPool.QueueUserWorkItem(_ => PausePrint()); } public static Task PausePrintAsync() { return Task.Run(()
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: Employee Self Service Timecard Entry © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

customer.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

MIX 09 4/17/2018 4:41 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
TechEd /6/2018 6:15 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
WebView: Bringing the web to your app
TechEd /26/2018 3:42 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Build /4/2018 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Windows Azure Jason Olson, Program Manager 4-142
Возможности Excel 2010, о которых следует знать
0 to 60: Developing Apps for Microsoft Office 2013
Building modern web applications with Visual Studio and Web Essentials
Title of Presentation 11/22/2018 3:34 PM
Visual Studio 2013 for web developers
Build /2/ The future of Azure devops: Building and managing cloud applications lifecycle across your teams Bradley Millington Program.
12/2/2018 4:10 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Title of Presentation 12/2/2018 3:48 PM
TechEd /6/2018 8:16 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
TechEd /9/ :20 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
TechEd /9/2018 4:17 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
1/3/2019 1:21 PM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
TechEd /23/2019 7:16 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
TechEd /3/ :48 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Build /10/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
IE11’s Developer Tools, F12, just got nicer (again)
Silverlight Debugging
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
What's New in Visual Studio & Blend for XAML Developers
4/27/17, Bell #8 What amount of net pay has been earned this period?
SharePoint 2013 Authentication with Azure – Part 1
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
WINDOWS AZURE A LAP AROUND PLATFORM THE Steve Marx
TechEd /27/2019 5:37 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
PENSACOLA ENERGY WORK PLAN OCTOBER 10, 2016
Jason Zander Unplugged
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Build /20/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Title of Presentation 5/24/2019 1:26 PM
5/24/2019 6:44 PM 1/8/18 Bell #10 In a world governed by the gods, is there any room for human will? Do human choices make a difference? EXPLAIN © 2007.
Title of Presentation 7/24/2019 8:53 PM
TechEd /30/2019 7:18 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
TechEd /5/2019 2:08 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
TechEd /21/2019 9:49 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
Presentation transcript:

Build 2012 1/2/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Async’ing Your Way to a Successful App with .NET Windows Azure 1/2/2019 Async’ing Your Way to a Successful App with .NET Stephen Toub Visual Studio 3-301 © 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Agenda 6 Tips for Building Better Apps

Wrap Events with Tasks to Improve Control Flow #1 Library Support TaskCompletionSource<T> Can be used to wrap arbitrary operations as a Task Once operations are exposed as Tasks, you can compose over them as you would any Task Pattern public Task<T> FooAsync() { var tcs = new TaskCompletionSource<T>(); // schedule something asynchronously // to invoke tcs.Set* return tcs.Task; } public Task Delay(int milliseconds) { var tcs = new TaskCompletionSource<bool>(); new Timer(_ => tcs.SetResult(true)).Change(milliseconds, -1); return tcs.Task; } public async Task RunStoryboardAsync(this Storyboard sb) { var tcs = new TaskCompletionSource<bool>(); EventHandler<object> handler = (s,e) => tcs.SetResult(true); sb.Completed += handler; sb.Begin(); await tcs.Task; sb.Completed -= handler; } public Task<T> RunAsync(Func<T> func) { var tcs = new TaskCompletionSource<T>(); ThreadPool.QueueUserWorkItem(delegate { try { tcs.SetResult(func()); } catch (Exception e) { tcs.SetException(e); } }); return tcs.Task; } public async Task WaitForClickAsync(this Button button) { var tcs = new TaskCompletionSource<bool>(); RoutedEventHandler handler = (s,e) => tcs.SetResult(true); button.Click += handler; await tcs.Task; button.Click -= handler; }

Wrapping Events with Tasks to Improve Control Flow Build 2012 1/2/2019 Wrapping Events with Tasks to Improve Control Flow Awaiting tasks makes it easy to compose sequences or graphs of operations. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Use Cancellation to Improve Responsiveness #2 Library Support CancellationToken as a composable cancellation mechanism var cts = new CancellationTokenSource(); SomeMethod(cts.Token); cts.Cancel(); Pattern public async Task FooAsync() { … await SomeDotNetAsync(); await SomeWinRTAsync(); } public async Task FooAsync(CancellationToken cancellationToken) { … await SomeDotNetAsync(cancellationToken); await SomeWinRTAsync().AsTask(cancellationToken); }

Using Cancellation to Improve Responsiveness Build 2012 1/2/2019 Using Cancellation to Improve Responsiveness Responsiveness isn’t just about keeping the UI available for interaction. More broadly, it’s about doing what the user wants when the user wants. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Be Wary of “Async Void” Language Support Guidance #3 async void, async Task, & async Task<T> async Task & async Task<T> return handles to the outstanding work async void is a “fire-and-forget” mechanism Guidance Use async void methods only for top-level entry points (e.g. UI event handlers) (Use and await async Task-returning methods everywhere else) Avoid passing async lambdas to void-returning delegates (Don’t pass async lambdas to WinRT methods unless you really know what you’re doing)

Build 2012 1/2/2019 Avoiding “async void” Many problems in async code can be traced back to using “async void” incorrectly. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Use ConfigureAwait for Perf & Responsiveness #4 SynchronizationContext represents a target for work DispatcherSynchronizationContext (Post: Dispatcher.BeginInvoke) WinRTSynchronizationContext (Post: CoreDispatcher.RunAsync) Await Behavior Guidance Use ConfigureAwait(false) on all awaits in all methods with code that’s context agnostic (which is most libraries) await task; // force continuation back to the current sync context await task.ConfigureAwait(false); // try to continue executing where awaited task completes

.ConfigureAwait(false) avoids deadlock. Using ConfigureAwait async void button1_Click(…) { await DoWorkAsync(); } async void button1_Click(…) { DoWorkAsync().Wait(); } async Task DoWorkAsync() { await Task.Run(…).ConfigureAwait(false); Console.WriteLine("Done task"); } async Task DoWorkAsync() { await Task.Run(…); Console.WriteLine("Done task"); } Use ConfigureAwait(false) 2. Task.Run schedules work to run on thread pool 1. DoWorkAsync invoked on UI thread 3. Await captures SynchronizationContext and hooks up a continuation to run when task completes 4. UI blocks waiting for DoWorkAsync-returned Task to complete 5. Task.Run task completes on pool & invokes continuation which Posts back to UI thread 6. UI thread still blocked waiting for async operation to complete. Deadlock! .ConfigureAwait(false) avoids deadlock.

Using ConfigureAwait for Responsiveness & Perf Build 2012 1/2/2019 Using ConfigureAwait for Responsiveness & Perf Avoiding using the UI thread unless you actually need to. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Avoid “Sync over Async”, “Async over Sync” in Libraries #5

What does asynchrony really mean? Synchronous Perform something here and now. I’ll regain control to execute something else when it’s done. Asynchronous Initiate something here and now. I’ll regain control to execute something else “immediately”.

Sync vs Async Synchronous Asynchronous TechReady 16 1/2/2019 Sync vs Async “Pause for 10 seconds, then output 'Hello' to the console.” Synchronous Asynchronous public static void PausePrint() { var end = DateTime.Now + TimeSpan.FromSeconds(10); while(DateTime.Now < end); Console.WriteLine("Hello"); } public static void PausePrintAsync() { ThreadPool.QueueUserWorkItem(_ => PausePrint()); } public static Task PausePrintAsync() { return Task.Run(() => PausePrint()); } “async over sync” Possible scalability problems public static void PausePrint() { Task t = PausePrintAsync(); t.Wait(); } public static async Task PausePrintAsync() { await Task.Delay(10000); Console.WriteLine("Hello"); } public static Task PausePrintAsync() { var tcs = new TaskCompletionSource<bool>(); new Timer(_ => { Console.WriteLine("Hello"); tcs.SetResult(true); }).Change(10000, Timeout.Infinite); return tcs.Task; } “sync over async” Possible responsiveness problems © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Avoid “Sync over Async”, “Async over Sync” in Libraries #5 Guidance Be honest! Suffix should help caller to understand implementation. Define “FooAsync” iff you’re not thread-bound (with a few notable exceptions). Don’t just expose FooAsync as “return Task.Run(() => Foo());” Define “Foo” iff you have a faster sync implementation that won’t deadlock. Don’t just expose Foo as “FooAsync().Wait();” Exceptions Methods exposed from .WinMD assemblies Overrides in some class hierarchies

Use Visual Studio’s async tooling #6 Visual Studio 2012: Stepping with Async Step In Step Over Step Out

Stepping in, over, and out with async Build 2012 1/2/2019 Stepping in, over, and out with async Stepping through your code as if it were synchronous. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Debugging Async in Visual Studio 2013 #7 Visual Studio 2013: Call Stack Window Provides a “call stack” across async points. Visual Studio 2013: Tasks Window See and navigate from a list all active async operations.

Using the Call Stack and Task Windows with async Build 2012 1/2/2019 Using the Call Stack and Task Windows with async Knowing how you got here and what’s going on © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Questions? Comments? Summary 6 Tips for Building Better Apps Wrap events with tasks to improve control flow Use cancellation to improve responsiveness Be wary of “async void” Use ConfigureAwait to improve perf & responsiveness Avoid exposing “sync over async” or “async over sync” Use Visual Studio’s async tooling Questions? Comments?

Resources Parallel Programming in .NET Blog: http://blogs.msdn.com/pfxteam Task-based Async Pattern Whitepaper http://aka.ms/tap

1/2/2019 7:34 PM Required Slide *delete this box when your slide is finalized Your MS Tag will be inserted here during the final scrub. Evaluate this session Scan this QR code to evaluate this session and be automatically entered in a drawing to win a prize! © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.