Upload
microsoft-developpeurs
View
607
Download
0
Embed Size (px)
DESCRIPTION
Dans sa dernière mouture, C# vous propose depuis un an le support de l’asynchronisme. Bien qu’ayant moi-même déjà présenté des sessions sur ce sujet, je vous propose ici de vous partager une compréhension plus avancée ainsi que des nouveaux modèles de programmation que j’ai pu découvrir et mettre en œuvre dans mes propres projets.
Citation preview
Code/Developpement
C# Async, un an après
Mitsuru FURUTACTO
[email protected], http://mitsufu.wordpress.com,
@mitsufu
Code/developpement#mstechdays
Depuis votre smartphone sur :http://notes.mstechdays.fr
De nombreux lots à gagner toute les heures !!!Claviers, souris et jeux Microsoft…
Merci de nous aider à améliorer les Techdays !
Donnez votre avis !
Code/developpement#mstechdays
• Introduction/Rappels• Comment ça marche ?• Synchronisation
– SynchronizableThread• SequentialTask
– Relance automatique sans thread supplémentaire• Q&A
Agenda
Code/developpement#mstechdays
• Intégré à C# 5/.Net 4.5• Evolution du langage + librairies• Asynchrone != parallèle• Async/Await
– Écriture linéaire des callbacks asynchrones (mono ou multi-thread)
– Chainage d’appels à travers un moteur à état– Encapsulation automatique de Task pour les méthodes async
• Awaitable pattern
Introduction/Rappels
démoCode/developpement
#mstechdays
Rappels
Code/developpement#mstechdays
• “Awaitable” pattern– public object GetAwaiter();
• INotifyCompletion• Public bool IsCompleted { get; }• public object GetResult();
Comment ça marche ?
public interface IAwaitable<out TResult>{ IAwaiter<TResult> GetAwaiter();}public interface IAwaiter<out TResult> : INotifyCompletion // or ICriticalNotifyCompletion{ bool IsCompleted { get; } TResult GetResult();}
démoCode/developpement
#mstechdays
manuellement
« Awaitable » pattern
Code/developpement#mstechdays
• Par méthode d’extension• CallContext
– Logical context
Comment ça marche ?
démoCode/developpement
#mstechdays
Par méthode d’extension
« Awaitable » pattern
Code/developpement#mstechdays
• Le retour d’un await revient automatiquement au thread appellant– Par quel mécanisme ?– Notion “ambiante”
• Qu’est-ce le SynchronizationContext ?• ConfigureAwait()
• Contexte de synchronization inexistant ?– Comportement par défaut– Comment en créer un soi-même ?
Contexte de synchronisation
démoCode/developpement
#mstechdays
SynchronizableThread
démoCode/developpement
#mstechdays
SequentialTask
© 2014 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.
Digital is business