1 / 31

Building mixed-language apps

Building mixed-language apps. Alan Ludwig Senior Software Development Engineer 4-100. The Windows Runtime makes it possible for you to write great apps using more than one language. The Windows Runtime (WinRT). APIs. Cross-language i nfrastructure. A version of Windows.

fedora
Download Presentation

Building mixed-language apps

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. Building mixed-language apps Alan Ludwig Senior Software Development Engineer 4-100

  2. The Windows Runtime makes it possible for you to write great apps using more than one language

  3. The Windows Runtime (WinRT) APIs Cross-language infrastructure A versionof Windows

  4. What’s the best language foryour Windows 8 apps? • The language you already know • The language your component is already written in • The language that has access to the features you need • The language that provides the right performance • The language of your choice

  5. How do I do that? • When you write a Windows Runtime component,you can consume it in JavaScript, C#/VB, or C++

  6. The same cross-language infrastructure that was used to create thousands of Windows Runtime APIs is available for you to write your own Windows Runtime APIs

  7. Hybrid JavaScript and C++ Sample • Demo

  8. How do I make it great? • Only where needed • Keep it simple • Async everywhere • Mind your threads

  9. Only where needed • Indirect function calls • Type conversion

  10. Examples of type conversion

  11. Keep it simple • Designing good Windows Runtime interfaces is similarto good OO design

  12. Async everywhere • Use the async pattern for long running operations • The language projections make this easy

  13. Async operation in C++ • Windows::Foundation::IAsyncOperation<uint32>^ DemoLib::GetCountAsync() • { • auto async = concurrency::create_async( • // your lambda here • [this](){ return _count;} • ); • return async; • }

  14. Async operation in C# • public Windows.Foundation.IAsyncOperation<UInt32> GetCountAsync() • { • return (Windows.Foundation.IAsyncOperation<UInt32>)Task<UInt32>.Run( () => {return _count;} • ); • }

  15. Mind your threads • Writing great components requires some basic knowledge of threading issues

  16. UI is always thread affine

  17. Threading UI Thread Callasync API Create task Other work Update UI Continue Worker Thread Do work Call completion How do I get back to the main thread?

  18. Techniques to get back to the main thread • Dispatching via the UI element • Dispatching via the core window • Proxies and stubs

  19. Dispatching via the UI element • if (output->Dispatcher->HasThreadAccess()) • { • output->Text += "Count Changed (thread access)! Count is " + • newCount.ToString() + "\n"; • }

  20. Dispatching via the UI element • else{ • output->Dispatcher->RunAsync( • Windows::UI::Core::CoreDispatcherPriority::Normal, • ref new Windows::UI::Core::DispatchedHandler( • [this, newCount]() -> void { • output->Text += "Count Changed (no thread access)! Count is • " + newCount.ToString() + "\n";})); • }

  21. Dispatching via the core window • Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync( • Windows::UI::Core::CoreDispatcherPriority::Normal, • ref new Windows::UI::Core::DispatchedHandler( • [this,value](){ • CountChanged(this, value);} • ));

  22. The Windows Runtime will automatically move your calls back to the right thread if proxies and stubs are available

  23. EventHandler vs. TypedEventHandler • event Windows::Foundation::EventHandler<uint32>^ CountChanged; • event Windows::Foundation::TypedEventHandler<IDemoLib^, uint32>^ CountChanged;

  24. Create proxies and stubs for yourWindows Runtime components

  25. Creating a Windows Runtime in-process component sample (C++/CX) • Demo

  26. The same cross-language infrastructure that was used to create thousands of Windows Runtime APIs is available for you to write your own Windows Runtime APIs

  27. How do I make it great? • Only where needed • Keep it simple • Async everywhere • Mind your threads

  28. Related Sessions • 10/30/2012 11:45 – B33 Baker – Bringing existing C++ code to Windows Store apps • 11/1/2012 12:00 – B33 Hood – Gaming reimagined: Gaming case studies A list of sessions will be sent one week prior to the event

  29. Resources • Hybrid JavaScriptand C++ sample • Creating a Windows Runtime in-process component sample (C++/CX) Please submit session evals by using the Build Windows 8 app or at http://aka.ms/BuildSessions

  30. Resources • Develop: http://msdn.microsoft.com/en-US/windows/apps/br229512 • Design: http://design.windows.com/ • Samples: http://code.msdn.microsoft.com/windowsapps/Windows-8-Modern-Style-App-Samples • Videos: http://channel9.msdn.com/Windows Please submit session evals by using the Build Windows 8 app or at http://aka.ms/BuildSessions

More Related