1 / 16

Async CTP in action

Async CTP in action. Владимир Барсуков UserGroup Красноярск Microsoft. Visual Studio Asynchronous Programming. Visual Studio 2010 SP1 Async CTP (  Community Technology Preview  ) Visual Studio 11 Developer preview ( Async is now available  ). Asynchronous Patterns.

Download Presentation

Async CTP in action

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Async CTP in action Владимир Барсуков UserGroupКрасноярск Microsoft

  2. Visual Studio Asynchronous Programming • Visual Studio 2010 SP1Async CTP ( Community Technology Preview ) • Visual Studio 11 Developer preview (Asyncis now available )

  3. Asynchronous Patterns • Asynchronous Programming Model (APM) • Event-based Asynchronous Pattern (EAP) • Task-based Asynchronous Pattern (TAP)

  4. Asynchronous Programming Model publicclassMyClass {         publicintRead(byte[] buffer, int offsetintcount); } ... publicclassMyClass {         publicIAsyncResult BeginRead(byte[] buffer, int offset, intcount,AsyncCallback callback, object state); publicint EndRead(IAsyncResult asyncResult);          }

  5. Event-based Asynchronous Pattern (EAP) publicclassMyClass   {           publicvoid ReadAsync(byte[] buffer, int offset, int count);          publiceventReadCompletedEventHandler ReadCompleted;         }    publicdelegatevoidReadCompletedEventHandler(       object sender, ReadCompletedEventArgs eventArgs);     publicclassReadCompletedEventArgs : AsyncCompletedEventArgs          {    publicint Result { get; }          }

  6. Task-based Asynchronous Pattern (TAP) publicclassMyClass  {        publicTask<int> ReadAsync(byte[] buffer, int offset, int count);          }

  7. Taskand Task<TResult > • “Представляет асинхронную операцию.” from msdn • В CLR 4 был определен тип Task<T> — рабочая лошадка TaskParallelLibrary (TPL), — представляющий концепцию «некоей работы, которая в будущем даст результат типа T». Концепция «работы, которая завершится в будущем, но не вернет никаких результатов» представлена необобщенным типом Task. • Пример создания задачи с помощью Factory свойства. vart = Task<int>.Factory.StartNew(()=>GenerateResult());

  8. Магические слова asyncи await

  9. TaskExдополнительные методы • TaskEx.WhenAll

  10. TaskExдополнительные методы • TaskEx.WhenAny and CancelationToken

  11. APM toTAP

  12. EAP toTAP

  13. Заключение • Async CTP дает нам возможность легко управлять большим количеством асинхронных методов • Исходный код становится удобочитаемым и сопровождаемым • Увеличивается производительность.

  14. Дополнительные материалыи ссылки • http://msdn.microsoft.com/en-us/magazine/hh463583.aspx • http://www.techdays.ru/ • http://msdn.microsoft.com/ru-ru/library/dd537609.aspx • http://msdn.microsoft.com/en-us/async

More Related