23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

else<br />

{<br />

localSettings.Values["InternetProfile"] = profile.ProfileName;<br />

}<br />

var networkAdapterInfo = profile.NetworkAdapter;<br />

if (networkAdapterInfo == null)<br />

{<br />

localSettings.Values["NetworkAdapterId"] =<br />

"Not connected to Internet";<br />

}<br />

else<br />

{<br />

localSettings.Values["NetworkAdapterId"] =<br />

networkAdapterInfo.NetworkAdapterId.ToString();<br />

}<br />

}<br />

}<br />

catch (Exception e)<br />

{<br />

// Debug output omitted<br />

}<br />

}<br />

}<br />

// Handles background task cancellation.<br />

private void OnCanceled(IBackgroundTaskInstance sender,<br />

BackgroundTaskCancellationReason reason)<br />

{<br />

// Debug output omitted<br />

}<br />

You can see that the Run method receives an argument through which it can register a handler for<br />

canceling the task. The code above doesn’t do anything meaningful with this because the task itself<br />

executes only a small amount of code. The C# tasks in the Background tasks sample, on the other hand,<br />

simulate longer-running operations, in which case it uses the handler to set a flag that will stop those<br />

operations.<br />

Access to Additional APIs<br />

Between the DOM API, WinJS, third-party libraries, and JavaScript intrinsics, JavaScript developers have<br />

no shortage of APIs to utilize in their apps. At the same time, there is a whole host of .NET and<br />

Win32/COM APIs that are available to C#, VB, and C++ apps that are not directly available to JavaScript,<br />

including the DirectX and Media Foundation APIs.<br />

With the exception of APIs that affect UI or drawing surfaces (namely Direct2D and Direct3D), WinRT<br />

components can make such functions—or, more likely, higher-level operations built with<br />

them—available to apps written in JavaScript.<br />

750

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!