<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Damir's Corner - Development|Metro</title>
    <link>http://www.damirscorner.com/</link>
    <description>Notes from Daily Encounters with Technology</description>
    <language>en-us</language>
    <copyright>Damir Arh, M. Sc.</copyright>
    <lastBuildDate>Mon, 20 May 2013 04:00:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>damir.arh@gmail.com</managingEditor>
    <webMaster>damir.arh@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=90166266-0d15-44c2-b437-654ca16abb42</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,90166266-0d15-44c2-b437-654ca16abb42.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,90166266-0d15-44c2-b437-654ca16abb42.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=90166266-0d15-44c2-b437-654ca16abb42</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently I encountered strange and inconsistent behavior in exceptions being thrown
by different file operations in WinRT. Let’s start with a snippet:
</p>
        <script src="https://gist.github.com/damirarh/5520351.js">
        </script>
        <p>
Although there is a file named Text.txt in Assets folder of the application package,
the above code throws an exception. If you were paying close attention while reading
the code you might have even noticed the problem. There’s no exception thrown in the
first line, though. Instead the second line throws an ArgumentException: Value does
not fall within the expected range. Strange, isn’t it?
</p>
        <p>
Let’s take a closer look by putting a breakpoint on the second line. The problem lies
in the value of file.Path property: C:\Users\Username\Documents\Visual Studio 2012\Projects\SlnName\ProjName\bin\Debug\AppX\\Assets\Text.txt.
Did you notice the two backslashes before the Assets folder? They’re causing the problem.
CopyAsync method can’t find the file because of it and throws the non-descriptive
exception which doesn’t really help pinpointing its cause. Calling ReadTextAsync on
the file instead would’ve make it much easier:
</p>
        <script src="https://gist.github.com/damirarh/5520383.js">
        </script>
        <p>
In this case the second line throws FileNotFoundException: The filename, directory
name, or volume label syntax is incorrect. Definitely much clearer. Too bad, CopyAsync
doesn’t throw the same exception. It would have made troubleshooting the original
issue much easier.
</p>
        <p>
That’s not all, though. I still think the exception should already be thrown in the
first line. If we replace the filename with a non-existent one (e.g. Text1.txt), it
does throw FileNotFoundException as expected: The system cannot find the file specified.
It seems that for some reason GetFileAsync can handle paths with double backslashes.
It even sets file.DateCreated correctly, so there can be no doubt about that. The
other methods don’t seem to support this same syntax. That’s not a problem per se,
but in my opinion all methods should behave the same to avoid confusion: either support
the syntax or not. Until that happens, I’ll keep in mind the described anomaly, just
in case I stumble upon it again.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=90166266-0d15-44c2-b437-654ca16abb42" />
      </body>
      <title>Inconsistent Exceptions for WinRT File Operations</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,90166266-0d15-44c2-b437-654ca16abb42.aspx</guid>
      <link>http://www.damirscorner.com/InconsistentExceptionsForWinRTFileOperations.aspx</link>
      <pubDate>Mon, 20 May 2013 04:00:00 GMT</pubDate>
      <description>&lt;p&gt;
Recently I encountered strange and inconsistent behavior in exceptions being thrown
by different file operations in WinRT. Let’s start with a snippet:
&lt;/p&gt;
&lt;script src="https://gist.github.com/damirarh/5520351.js"&gt;&lt;/script&gt;
&lt;p&gt;
Although there is a file named Text.txt in Assets folder of the application package,
the above code throws an exception. If you were paying close attention while reading
the code you might have even noticed the problem. There’s no exception thrown in the
first line, though. Instead the second line throws an ArgumentException: Value does
not fall within the expected range. Strange, isn’t it?
&lt;/p&gt;
&lt;p&gt;
Let’s take a closer look by putting a breakpoint on the second line. The problem lies
in the value of file.Path property: C:\Users\Username\Documents\Visual Studio 2012\Projects\SlnName\ProjName\bin\Debug\AppX\\Assets\Text.txt.
Did you notice the two backslashes before the Assets folder? They’re causing the problem.
CopyAsync method can’t find the file because of it and throws the non-descriptive
exception which doesn’t really help pinpointing its cause. Calling ReadTextAsync on
the file instead would’ve make it much easier:
&lt;/p&gt;
&lt;script src="https://gist.github.com/damirarh/5520383.js"&gt;&lt;/script&gt;
&lt;p&gt;
In this case the second line throws FileNotFoundException: The filename, directory
name, or volume label syntax is incorrect. Definitely much clearer. Too bad, CopyAsync
doesn’t throw the same exception. It would have made troubleshooting the original
issue much easier.
&lt;/p&gt;
&lt;p&gt;
That’s not all, though. I still think the exception should already be thrown in the
first line. If we replace the filename with a non-existent one (e.g. Text1.txt), it
does throw FileNotFoundException as expected: The system cannot find the file specified.
It seems that for some reason GetFileAsync can handle paths with double backslashes.
It even sets file.DateCreated correctly, so there can be no doubt about that. The
other methods don’t seem to support this same syntax. That’s not a problem per se,
but in my opinion all methods should behave the same to avoid confusion: either support
the syntax or not. Until that happens, I’ll keep in mind the described anomaly, just
in case I stumble upon it again.
&lt;/p&gt;
&gt;&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=90166266-0d15-44c2-b437-654ca16abb42"/&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,90166266-0d15-44c2-b437-654ca16abb42.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/C#</category>
      <category>Development/Metro</category>
      <category>Development/Windows Store</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=030406ab-a26f-469e-bde3-8ccd45da33e3</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,030406ab-a26f-469e-bde3-8ccd45da33e3.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,030406ab-a26f-469e-bde3-8ccd45da33e3.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=030406ab-a26f-469e-bde3-8ccd45da33e3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://msdn.microsoft.com/en-us/library/hh873175.aspx">Task-based asynchronous
pattern</a> has many advantages over other asynchronous patterns introduced in the
past, most of them boiling down to the fact that it’s really easy to get into and
start using it. Like any other technology, it does have its pitfalls and there are
many details to know about once you get into more advanced scenarios.
</p>
        <p>
One of the first issues you’ll very probably stumble upon, is the viral nature of
asynchronous methods, meaning that as soon as a method calls one asynchronous method,
it becomes asynchronous as well. In most cases that’s not really a problem: you just
change method signatures by adding the async keyword and changing the return value
(T to Task&lt;T&gt; and void to Task) up the call stack until you reach the originating
call, usually an event handler. You just make it async void and you’re done.
</p>
        <p>
The problem arises when you’re trying to call such an asynchronous method from a class
constructor: you can’t use the await keyword inside the constructor. As long as you’re
only using methods which don’t return a value, you can get away with it by just calling
them without await, but that’s not the right way to do it. That’s why the compiler
issues a warning in this case: Because this call is not awaited, execution of the
current method continues before the call is completed. Consider applying the 'await'
operator to the result of the call.
</p>
        <p>
Of course, there are ways to properly get around this limitation. Most of the time
you don’t care when the asynchronous part of the constructor is going to be completed.
This happens in view models, for example. You start loading data in the constructor
and when its loaded, the values get assigned to public properties implementing INotifyPropertyChanged
interface and in turn cause the UI to refresh. In this case all asynchronous calls
can be grouped in a single async void asynchronous method which can be called from
the constructor:
</p>
        <script src="https://gist.github.com/damirarh/5520143.js">
        </script>
        <p>
You can expand on that same idea by adding a bool Initialized property to your view
model. By setting it to true at the end of Init(), you can use it to display a different
view (e.g. an indeterminate progress indicator) until the initialization is complete
(I added a short delay to make the effect easier to notice):
</p>
        <script src="https://gist.github.com/damirarh/5520196.js">
        </script>
        <p>
The next improvement on the idea would be providing progress report during initial
loading. Since everything is being processed inside the same view model class, this
could be achieved in many ways, but lets take the IProgress&lt;T&gt; approach as defined
by the task-based asynchronous pattern (again I’m using delays to simulate loading
times):
</p>
        <script src="https://gist.github.com/damirarh/5520235.js">
        </script>
        <p>
If you don’t want a loading view but need to check whether initialization is complete
at a later time you can change Init() to return a task and store a reference to it:
</p>
        <script src="https://gist.github.com/damirarh/5520255.js">
        </script>
        <p>
Using one of the techniques above you should be able to call any asynchronous method
in a class constructor and handle it appropriately. As always modify the implementation
details to your actual needs.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=030406ab-a26f-469e-bde3-8ccd45da33e3" />
      </body>
      <title>Calling Task-based Asynchronous Methods from Class Constructors</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,030406ab-a26f-469e-bde3-8ccd45da33e3.aspx</guid>
      <link>http://www.damirscorner.com/CallingTaskbasedAsynchronousMethodsFromClassConstructors.aspx</link>
      <pubDate>Mon, 06 May 2013 10:00:00 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/hh873175.aspx"&gt;Task-based asynchronous
pattern&lt;/a&gt; has many advantages over other asynchronous patterns introduced in the
past, most of them boiling down to the fact that it’s really easy to get into and
start using it. Like any other technology, it does have its pitfalls and there are
many details to know about once you get into more advanced scenarios.
&lt;/p&gt;
&lt;p&gt;
One of the first issues you’ll very probably stumble upon, is the viral nature of
asynchronous methods, meaning that as soon as a method calls one asynchronous method,
it becomes asynchronous as well. In most cases that’s not really a problem: you just
change method signatures by adding the async keyword and changing the return value
(T to Task&amp;lt;T&amp;gt; and void to Task) up the call stack until you reach the originating
call, usually an event handler. You just make it async void and you’re done.
&lt;/p&gt;
&lt;p&gt;
The problem arises when you’re trying to call such an asynchronous method from a class
constructor: you can’t use the await keyword inside the constructor. As long as you’re
only using methods which don’t return a value, you can get away with it by just calling
them without await, but that’s not the right way to do it. That’s why the compiler
issues a warning in this case: Because this call is not awaited, execution of the
current method continues before the call is completed. Consider applying the 'await'
operator to the result of the call.
&lt;/p&gt;
&lt;p&gt;
Of course, there are ways to properly get around this limitation. Most of the time
you don’t care when the asynchronous part of the constructor is going to be completed.
This happens in view models, for example. You start loading data in the constructor
and when its loaded, the values get assigned to public properties implementing INotifyPropertyChanged
interface and in turn cause the UI to refresh. In this case all asynchronous calls
can be grouped in a single async void asynchronous method which can be called from
the constructor:
&lt;/p&gt;
&lt;script src="https://gist.github.com/damirarh/5520143.js"&gt;&lt;/script&gt;
&lt;p&gt;
You can expand on that same idea by adding a bool Initialized property to your view
model. By setting it to true at the end of Init(), you can use it to display a different
view (e.g. an indeterminate progress indicator) until the initialization is complete
(I added a short delay to make the effect easier to notice):
&lt;/p&gt;
&lt;script src="https://gist.github.com/damirarh/5520196.js"&gt;&lt;/script&gt;
&lt;p&gt;
The next improvement on the idea would be providing progress report during initial
loading. Since everything is being processed inside the same view model class, this
could be achieved in many ways, but lets take the IProgress&amp;lt;T&amp;gt; approach as defined
by the task-based asynchronous pattern (again I’m using delays to simulate loading
times):
&lt;/p&gt;
&lt;script src="https://gist.github.com/damirarh/5520235.js"&gt;&lt;/script&gt;
&lt;p&gt;
If you don’t want a loading view but need to check whether initialization is complete
at a later time you can change Init() to return a task and store a reference to it:
&lt;/p&gt;
&lt;script src="https://gist.github.com/damirarh/5520255.js"&gt;&lt;/script&gt;
&lt;p&gt;
Using one of the techniques above you should be able to call any asynchronous method
in a class constructor and handle it appropriately. As always modify the implementation
details to your actual needs.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=030406ab-a26f-469e-bde3-8ccd45da33e3" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,030406ab-a26f-469e-bde3-8ccd45da33e3.aspx</comments>
      <category>Development</category>
      <category>Development/.NET 4.5</category>
      <category>Development/C#</category>
      <category>Development/Metro</category>
      <category>Development/Windows Store</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=59faa4a2-fba0-483f-a56f-393662ad38a5</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,59faa4a2-fba0-483f-a56f-393662ad38a5.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,59faa4a2-fba0-483f-a56f-393662ad38a5.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=59faa4a2-fba0-483f-a56f-393662ad38a5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
On the final day of NT Conference 2013 I had my last session. This time I was speaking
about my experiences with building LOB (line of business) applications for Windows
Store. As always, <a href="http://www.slideshare.net/xAmigan/windows-store-lob-apps-v-poslovnih-okoljih">slides</a> and <a href="https://bitbucket.org/damirarh/ntk2013-windowsstorelob">samples</a> are
available here and from the conference web site.
</p>
        <p align="center">
          <iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" height="356" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/20078617" frameborder="0" width="427" marginwidth="0" scrolling="no" mozallowfullscreen="mozallowfullscreen" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen">
          </iframe>
        </p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=59faa4a2-fba0-483f-a56f-393662ad38a5" />
      </body>
      <title>Windows Store LOB Apps Session at NT Conference 2013</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,59faa4a2-fba0-483f-a56f-393662ad38a5.aspx</guid>
      <link>http://www.damirscorner.com/WindowsStoreLOBAppsSessionAtNTConference2013.aspx</link>
      <pubDate>Sat, 27 Apr 2013 13:28:20 GMT</pubDate>
      <description>&lt;p&gt;
On the final day of NT Conference 2013 I had my last session. This time I was speaking
about my experiences with building LOB (line of business) applications for Windows
Store. As always, &lt;a href="http://www.slideshare.net/xAmigan/windows-store-lob-apps-v-poslovnih-okoljih"&gt;slides&lt;/a&gt; and &lt;a href="https://bitbucket.org/damirarh/ntk2013-windowsstorelob"&gt;samples&lt;/a&gt; are
available here and from the conference web site.
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" height="356" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/20078617" frameborder="0" width="427" marginwidth="0" scrolling="no" mozallowfullscreen webkitallowfullscreen allowfullscreen&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=59faa4a2-fba0-483f-a56f-393662ad38a5" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,59faa4a2-fba0-483f-a56f-393662ad38a5.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/Metro</category>
      <category>Development/Windows Store</category>
      <category>Downloads</category>
      <category>Downloads/Presentations</category>
      <category>Downloads/Sources</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=119874b7-da52-4b3e-9af8-ca14dea25450</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,119874b7-da52-4b3e-9af8-ca14dea25450.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,119874b7-da52-4b3e-9af8-ca14dea25450.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=119874b7-da52-4b3e-9af8-ca14dea25450</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
At <a href="http://www.ntk.si/">NT conference 2013</a> I opened the Windows 8 and
Windows Phone 8 Developer Tales from the Tranches PreCon track with a session on Building
Connected Apps. I addressed all aspects of network communications, focusing on available
APIs but also spending some time on the expectations for mobile applications in respect
to network usage.
</p>
        <p>
Although the session materials are already on the conference web site, I’m also publishing
them here to keep them available after the conference site is closed down: both <a href="http://www.slideshare.net/xAmigan/gradnja-povezanih-aplikacij">slides</a> and <a href="https://bitbucket.org/damirarh/ntk2013-connectedapps">samples</a>.
</p>
        <p align="center">
          <iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" height="356" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/20070540" frameborder="0" width="427" marginwidth="0" scrolling="no" mozallowfullscreen="mozallowfullscreen" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen">
          </iframe>
        </p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=119874b7-da52-4b3e-9af8-ca14dea25450" />
      </body>
      <title>Building Connected Apps Session at NT conference 2013</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,119874b7-da52-4b3e-9af8-ca14dea25450.aspx</guid>
      <link>http://www.damirscorner.com/BuildingConnectedAppsSessionAtNTConference2013.aspx</link>
      <pubDate>Sat, 27 Apr 2013 10:49:11 GMT</pubDate>
      <description>&lt;p&gt;
At &lt;a href="http://www.ntk.si/"&gt;NT conference 2013&lt;/a&gt; I opened the Windows 8 and
Windows Phone 8 Developer Tales from the Tranches PreCon track with a session on Building
Connected Apps. I addressed all aspects of network communications, focusing on available
APIs but also spending some time on the expectations for mobile applications in respect
to network usage.
&lt;/p&gt;
&lt;p&gt;
Although the session materials are already on the conference web site, I’m also publishing
them here to keep them available after the conference site is closed down: both &lt;a href="http://www.slideshare.net/xAmigan/gradnja-povezanih-aplikacij"&gt;slides&lt;/a&gt; and &lt;a href="https://bitbucket.org/damirarh/ntk2013-connectedapps"&gt;samples&lt;/a&gt;.
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" height="356" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/20070540" frameborder="0" width="427" marginwidth="0" scrolling="no" mozallowfullscreen webkitallowfullscreen allowfullscreen&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=119874b7-da52-4b3e-9af8-ca14dea25450" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,119874b7-da52-4b3e-9af8-ca14dea25450.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/Metro</category>
      <category>Development/Windows Store</category>
      <category>Development/WP</category>
      <category>Downloads</category>
      <category>Downloads/Presentations</category>
      <category>Downloads/Sources</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=5f21c3b9-8804-40a8-95e5-501cbde24f08</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,5f21c3b9-8804-40a8-95e5-501cbde24f08.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,5f21c3b9-8804-40a8-95e5-501cbde24f08.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5f21c3b9-8804-40a8-95e5-501cbde24f08</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today our local Microsoft DPE team organized ReBuild, a one day recap of the recent <a href="http://www.buildwindows.com/">Build
conference</a> which was taking place in Redmond a little over a month ago. I had
the last session of the day and focused on Windows Store apps: what they were and
how to develop them. 
</p>
        <p>
As always I’m publically sharing the resources from the session: <a href="http://www.slideshare.net/xAmigan/razvoj-aplikacij-za-windows-store">slide
deck</a> and <a href="https://bitbucket.org/damirarh/rebuild2012">sample source code</a>.
</p>
        <p align="center">
          <iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" height="356" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/15591379" frameborder="0" width="427" marginwidth="0" scrolling="no" mozallowfullscreen="mozallowfullscreen" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen">
          </iframe>
        </p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=5f21c3b9-8804-40a8-95e5-501cbde24f08" />
      </body>
      <title>Developing Windows Store Apps Session at ReBuild 2012</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,5f21c3b9-8804-40a8-95e5-501cbde24f08.aspx</guid>
      <link>http://www.damirscorner.com/DevelopingWindowsStoreAppsSessionAtReBuild2012.aspx</link>
      <pubDate>Tue, 11 Dec 2012 16:52:17 GMT</pubDate>
      <description>&lt;p&gt;
Today our local Microsoft DPE team organized ReBuild, a one day recap of the recent &lt;a href="http://www.buildwindows.com/"&gt;Build
conference&lt;/a&gt; which was taking place in Redmond a little over a month ago. I had
the last session of the day and focused on Windows Store apps: what they were and
how to develop them. 
&lt;/p&gt;
&lt;p&gt;
As always I’m publically sharing the resources from the session: &lt;a href="http://www.slideshare.net/xAmigan/razvoj-aplikacij-za-windows-store"&gt;slide
deck&lt;/a&gt; and &lt;a href="https://bitbucket.org/damirarh/rebuild2012"&gt;sample source code&lt;/a&gt;.
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" height="356" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/15591379" frameborder="0" width="427" marginwidth="0" scrolling="no" mozallowfullscreen webkitallowfullscreen allowfullscreen&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=5f21c3b9-8804-40a8-95e5-501cbde24f08" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,5f21c3b9-8804-40a8-95e5-501cbde24f08.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/C#</category>
      <category>Development/Metro</category>
      <category>Development/Windows Store</category>
      <category>Downloads</category>
      <category>Downloads/Presentations</category>
      <category>Downloads/Sources</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=eb34e62a-c5f9-4d21-9174-1e2a1db2f0f3</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,eb34e62a-c5f9-4d21-9174-1e2a1db2f0f3.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,eb34e62a-c5f9-4d21-9174-1e2a1db2f0f3.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=eb34e62a-c5f9-4d21-9174-1e2a1db2f0f3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This weekend a <a href="http://www.microsoft.com/student/en-us/wowzapp/default.aspx">worldwide
hackathon for Windows</a> is taking place in over 100 locations. Among them is <a href="http://www.microsoft.com/student/en-us/wowzapp/eventpage.aspx?drop=12">Ljubljana</a> where
the event started with my 3 hour Windows Store app development workshop. I split it
in two parts:
</p>
        <ul>
          <li>
In the first half I focused on the basics of Windows Store apps, their features, development
tools and the APIs available. 
</li>
          <li>
In the second half I live coded a simple RSS reader app based on the grid app template
featuring support for settings, share and search charms.</li>
        </ul>
        <p>
I less than an hour the developers are about to start their 24 hour development marathon.
I wish each and every one of them good luck and lots of success.
</p>
        <p>
To make their life a little bit easier here are the links to my <a href="http://www.slideshare.net/xAmigan/delavnica-za-razvoj-windows-8-aplikacij">slide
deck</a> and <a href="https://bitbucket.org/damirarh/wowreader">app source code</a>.
</p>
        <p align="center">
          <iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" height="356" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/15103782" frameborder="0" width="427" marginwidth="0" scrolling="no" mozallowfullscreen="mozallowfullscreen" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen">
          </iframe>
        </p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=eb34e62a-c5f9-4d21-9174-1e2a1db2f0f3" />
      </body>
      <title>Resources from Windows Store App Development Workshop</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,eb34e62a-c5f9-4d21-9174-1e2a1db2f0f3.aspx</guid>
      <link>http://www.damirscorner.com/ResourcesFromWindowsStoreAppDevelopmentWorkshop.aspx</link>
      <pubDate>Fri, 09 Nov 2012 19:17:23 GMT</pubDate>
      <description>&lt;p&gt;
This weekend a &lt;a href="http://www.microsoft.com/student/en-us/wowzapp/default.aspx"&gt;worldwide
hackathon for Windows&lt;/a&gt; is taking place in over 100 locations. Among them is &lt;a href="http://www.microsoft.com/student/en-us/wowzapp/eventpage.aspx?drop=12"&gt;Ljubljana&lt;/a&gt; where
the event started with my 3 hour Windows Store app development workshop. I split it
in two parts:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
In the first half I focused on the basics of Windows Store apps, their features, development
tools and the APIs available. 
&lt;li&gt;
In the second half I live coded a simple RSS reader app based on the grid app template
featuring support for settings, share and search charms.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I less than an hour the developers are about to start their 24 hour development marathon.
I wish each and every one of them good luck and lots of success.
&lt;/p&gt;
&lt;p&gt;
To make their life a little bit easier here are the links to my &lt;a href="http://www.slideshare.net/xAmigan/delavnica-za-razvoj-windows-8-aplikacij"&gt;slide
deck&lt;/a&gt; and &lt;a href="https://bitbucket.org/damirarh/wowreader"&gt;app source code&lt;/a&gt;.
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" height="356" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/15103782" frameborder="0" width="427" marginwidth="0" scrolling="no" mozallowfullscreen webkitallowfullscreen allowfullscreen&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=eb34e62a-c5f9-4d21-9174-1e2a1db2f0f3" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,eb34e62a-c5f9-4d21-9174-1e2a1db2f0f3.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/C#</category>
      <category>Development/Metro</category>
      <category>Development/Windows Store</category>
      <category>Downloads</category>
      <category>Downloads/Presentations</category>
      <category>Downloads/Sources</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=03167081-14bf-4755-95c4-43badd99ad9d</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,03167081-14bf-4755-95c4-43badd99ad9d.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,03167081-14bf-4755-95c4-43badd99ad9d.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=03167081-14bf-4755-95c4-43badd99ad9d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The 5th <a href="http://www.bleedingedge.si/Conference">Bleeding Edge</a> conference
was taking place in Laško. For my session I decided to take a different approach to
the development of Windows Store apps: instead of talking about the design or the
available APIs in WinRT, I focused on architectural best practices when using C#,
XAML and the MVVM pattern.
</p>
        <p>
The <a href="http://www.slideshare.net/xAmigan/c-xaml-in-mvvm">slides</a> from the
session are on SlideShare as always:
</p>
        <p align="center">
          <iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/14871847" marginwidth="0" allowfullscreen="" frameborder="0" height="356" scrolling="no" width="427">
          </iframe>
        </p>
        <p>
You can download the <a href="http://www.damirscorner.com/content/binary/BleedingEdge2012.zip">final
sources</a> for the demo application here or even better: access the <a href="https://bitbucket.org/damirarh/bleedingedge2012">Git
repository</a> with a separate branch for each demo from the session.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=03167081-14bf-4755-95c4-43badd99ad9d" />
      </body>
      <title>Developing Windows Store Apps with C#, XAML and MVVM Session from Bleeding Edge 2012</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,03167081-14bf-4755-95c4-43badd99ad9d.aspx</guid>
      <link>http://www.damirscorner.com/DevelopingWindowsStoreAppsWithCXAMLAndMVVMSessionFromBleedingEdge2012.aspx</link>
      <pubDate>Thu, 25 Oct 2012 18:13:56 GMT</pubDate>
      <description>&lt;p&gt;
The 5th &lt;a href="http://www.bleedingedge.si/Conference"&gt;Bleeding Edge&lt;/a&gt; conference
was taking place in Laško. For my session I decided to take a different approach to
the development of Windows Store apps: instead of talking about the design or the
available APIs in WinRT, I focused on architectural best practices when using C#,
XAML and the MVVM pattern.
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://www.slideshare.net/xAmigan/c-xaml-in-mvvm"&gt;slides&lt;/a&gt; from the
session are on SlideShare as always:
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/14871847" marginwidth="0" allowfullscreen="" frameborder="0" height="356" scrolling="no" width="427"&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;
You can download the &lt;a href="http://www.damirscorner.com/content/binary/BleedingEdge2012.zip"&gt;final
sources&lt;/a&gt; for the demo application here or even better: access the &lt;a href="https://bitbucket.org/damirarh/bleedingedge2012"&gt;Git
repository&lt;/a&gt; with a separate branch for each demo from the session.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=03167081-14bf-4755-95c4-43badd99ad9d" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,03167081-14bf-4755-95c4-43badd99ad9d.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/C#</category>
      <category>Development/Metro</category>
      <category>Development/Windows Store</category>
      <category>Downloads</category>
      <category>Downloads/Presentations</category>
      <category>Downloads/Sources</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=1fd28e2b-ddf0-4d07-8df4-21b516d992a6</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,1fd28e2b-ddf0-4d07-8df4-21b516d992a6.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,1fd28e2b-ddf0-4d07-8df4-21b516d992a6.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1fd28e2b-ddf0-4d07-8df4-21b516d992a6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you've tried accessing an OData feed from a Windows Store apps you've already come
across WCF Data Services Tools for Windows Store Apps. It's a <a href="http://www.microsoft.com/en-us/download/details.aspx?id=30714">downloadable
package</a> which extends the Add Service Reference functionality in Visual Studio
2012 to support OData feeds. Without it OData feeds can't be added as services references
to a Windows Store app project.
</p>
        <p>
The interesting thing about this installer is that it doesn't add the required references
(Microsoft.Data.OData.WindowsStore and Microsoft.Data.Services.Client.WindowsStore)
to the project directly but as NuGet packages instead. As it is also mentioned on
the download page, this will make it possible to update the packages directly via
NuGet. Unfortunately this approach also has a downside: at the time of writing these
two packages are not available on NuGet <a href="https://nuget.org/packages?q=Microsoft.Data.OData.WindowsStore&amp;prerelease=true&amp;sortOrder=relevance">at</a><a href="https://nuget.org/packages?q=Microsoft.Data.Services.Client.WindowsStore&amp;prerelease=true&amp;sortOrder=relevance">all</a>.
This is not a problem when you're working on the project from a single machine only,
but it will make building the project a challenge on another machine if you're retrieving
it from a source control system with NuGet package restore enabled. In this case the
required references will not be present in the packages subfolder of the solution
and NuGet will fail to restore them since it won't find them in the default package
source.
</p>
        <p>
The best way to make this work is to add another package source to NuGet, pointing
to your local folder where the downloaded installer has put the packages, i.e. c:\Program
Files (x86)\Microsoft WCF Data Services\5.0\bin\NuGet. I suggest you define it as
the secondary package source, so that after the packages are available directly from
NuGet, they will be retrieved from there instead from your local disk.
</p>
        <p>
You can add the package source either through Package Manager Settings in Visual Studio
Options window:
</p>
        <p>
          <img title="Package Manager Setting in Visual Studio" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Package Manager Setting in Visual Studio" src="http://www.damirscorner.com/content/binary/Windows-Live-Writer/3a2e25a31601_AEB8/image_5.png" width="600" height="350" />
        </p>
        <p>
Or by modifying the NuGet.config file:
</p>
        <pre class="brush: xml;">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;configuration&gt;
  &lt;packageSources&gt;
    &lt;add key="NuGet official package source" 
        value="https://go.microsoft.com/fwlink/?LinkID=206669" /&gt;
    &lt;add key="WCF Data Services Package Source" 
        value="c:\Program Files (x86)\Microsoft WCF Data Services\5.0\bin\NuGet\" /&gt;
  &lt;/packageSources&gt;
  &lt;activePackageSource&gt;
    &lt;add key="All" value="(Aggregate source)" /&gt;
  &lt;/activePackageSource&gt;
&lt;/configuration&gt;
</pre>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=1fd28e2b-ddf0-4d07-8df4-21b516d992a6" />
      </body>
      <title>WCF Data Services Tools for Windows Store Apps and NuGet Package Restore</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,1fd28e2b-ddf0-4d07-8df4-21b516d992a6.aspx</guid>
      <link>http://www.damirscorner.com/WCFDataServicesToolsForWindowsStoreAppsAndNuGetPackageRestore.aspx</link>
      <pubDate>Sun, 21 Oct 2012 10:28:16 GMT</pubDate>
      <description>&lt;p&gt;
If you've tried accessing an OData feed from a Windows Store apps you've already come
across WCF Data Services Tools for Windows Store Apps. It's a &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=30714"&gt;downloadable
package&lt;/a&gt; which extends the Add Service Reference functionality in Visual Studio
2012 to support OData feeds. Without it OData feeds can't be added as services references
to a Windows Store app project.
&lt;/p&gt;
&lt;p&gt;
The interesting thing about this installer is that it doesn't add the required references
(Microsoft.Data.OData.WindowsStore and Microsoft.Data.Services.Client.WindowsStore)
to the project directly but as NuGet packages instead. As it is also mentioned on
the download page, this will make it possible to update the packages directly via
NuGet. Unfortunately this approach also has a downside: at the time of writing these
two packages are not available on NuGet &lt;a href="https://nuget.org/packages?q=Microsoft.Data.OData.WindowsStore&amp;amp;prerelease=true&amp;amp;sortOrder=relevance"&gt;at&lt;/a&gt; &lt;a href="https://nuget.org/packages?q=Microsoft.Data.Services.Client.WindowsStore&amp;amp;prerelease=true&amp;amp;sortOrder=relevance"&gt;all&lt;/a&gt;.
This is not a problem when you're working on the project from a single machine only,
but it will make building the project a challenge on another machine if you're retrieving
it from a source control system with NuGet package restore enabled. In this case the
required references will not be present in the packages subfolder of the solution
and NuGet will fail to restore them since it won't find them in the default package
source.
&lt;/p&gt;
&lt;p&gt;
The best way to make this work is to add another package source to NuGet, pointing
to your local folder where the downloaded installer has put the packages, i.e. c:\Program
Files (x86)\Microsoft WCF Data Services\5.0\bin\NuGet. I suggest you define it as
the secondary package source, so that after the packages are available directly from
NuGet, they will be retrieved from there instead from your local disk.
&lt;/p&gt;
&lt;p&gt;
You can add the package source either through Package Manager Settings in Visual Studio
Options window:
&lt;/p&gt;
&lt;p&gt;
&lt;img title="Package Manager Setting in Visual Studio" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Package Manager Setting in Visual Studio" src="http://www.damirscorner.com/content/binary/Windows-Live-Writer/3a2e25a31601_AEB8/image_5.png" width="600" height="350"&gt;
&lt;/p&gt;
&lt;p&gt;
Or by modifying the NuGet.config file:
&lt;/p&gt;
&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;configuration&amp;gt;
  &amp;lt;packageSources&amp;gt;
    &amp;lt;add key="NuGet official package source" 
        value="https://go.microsoft.com/fwlink/?LinkID=206669" /&amp;gt;
    &amp;lt;add key="WCF Data Services Package Source" 
        value="c:\Program Files (x86)\Microsoft WCF Data Services\5.0\bin\NuGet\" /&amp;gt;
  &amp;lt;/packageSources&amp;gt;
  &amp;lt;activePackageSource&amp;gt;
    &amp;lt;add key="All" value="(Aggregate source)" /&amp;gt;
  &amp;lt;/activePackageSource&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=1fd28e2b-ddf0-4d07-8df4-21b516d992a6" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,1fd28e2b-ddf0-4d07-8df4-21b516d992a6.aspx</comments>
      <category>Development</category>
      <category>Development/Metro</category>
      <category>Development/NuGet</category>
      <category>Development/WCF</category>
      <category>Development/Windows Store</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=e4fa2f50-2ef0-471e-b0f3-c8d2e00e3c83</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,e4fa2f50-2ef0-471e-b0f3-c8d2e00e3c83.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,e4fa2f50-2ef0-471e-b0f3-c8d2e00e3c83.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e4fa2f50-2ef0-471e-b0f3-c8d2e00e3c83</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the important aspects of Windows Store application development is the application
lifecycle. While at first it might seem a minor detail that can be taken care of late
in the application development process, it can affect the application architecture
quite profoundly. Therefore it's a good idea to address it soon enough to avoid unplanned
refactoring when the application is almost complete.
</p>
        <p>
          <img title="Windows Store application lifecycle" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Windows Store application lifecycle" src="http://www.damirscorner.com/content/binary/Windows-Live-Writer/0fbdec84f825_115F2/clip_image001_3.png" width="615" height="293" />
        </p>
        <p>
Since the basics of Windows Store application lifecycle are <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx">well
documented</a>, I'm not going to repeat them here. Rather, I'm going to focus on a
single aspect of it: the transition between the running and the suspended state. During
this transition the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.application.suspending%28v=win.10%29.aspx">Application.Suspending</a> event
is called to allow the application to save its state to local storage which can be
used to resume the application in case it gets terminated.
</p>
        <p>
If you base your application on correct templates for Windows Store applications which
are included with Visual Studio 2012 this will already be mostly taken care of for
you. Both Grid App and Split App templates include a SuspensionManager class in their
Common folder and also call it at all the appropriate spots in the application. This
class can save the application state to the local storage into a file named _sessionState.xml
and later reload it. It includes the complete frame navigation history consisting
of the loaded pages and the parameters they were loaded with. As long as you only
need this parameter to completely restore the state of the page, you don't have to
do anything extra.
</p>
        <p>
          <img title="Debug Location toolbar in Visual Studio 2012" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Debug Location toolbar in Visual Studio 2012" src="http://www.damirscorner.com/content/binary/Windows-Live-Writer/0fbdec84f825_115F2/clip_image002_3.png" width="624" height="104" />
        </p>
        <p>
There's <a href="http://blogs.msdn.com/b/visualstudio/archive/2012/08/23/new-visual-studio-2012-debugging-features-for-the-windows-8-app-lifecycle-model.aspx">a
function in Visual Studio</a> that makes it easy to test that, it's just hidden in
its default configuration. To access it you first need to show the Debug Location
toolbar. There is a dropdown menu on it which is enabled only when the application
is running. It contains three items: Suspend, Resume, and Suspend and shutdown. The
last one is your friend when you want to test how your application resumes after it
has been terminated: just run the application, navigate to the page you want to test
and invoke the Suspend and shutdown action. The next time you run the application,
it should resume with the same state.
</p>
        <p>
Unfortunately you can easily break suspending and resuming in your application if
you pass a custom class as the page parameter. Try it out! For example you can replace
the UniqueId that's being passed between the GroupedItemsPage and GroupDetailPage
in the Grid App template with a complete instance of SampleDataGroup. If you now Suspend
and shutdown your application, the SuspensionManager.SaveAsync method will throw a
non-descriptive SuspensionManagerException: "SuspensionManager failed". Investigating
the call stack reveals that the failing method was actually <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.frame.getnavigationstate%28v=win.10%29.aspx">Frame.GetNavigationState</a> which
has thrown an easier to comprehend COMException (It sounds like an oxymoron, doesn't
it?): "WinRT information: GetNavigationState doesn't support serialization of a parameter
type which was passed to Frame.Navigate.".
</p>
        <p>
What can we do about it? As it turns out, not much. According to <a href="https://connect.microsoft.com/VisualStudio/feedback/details/753331/xaml-metro-app-complex-objects-as-parameter-when-navigating-between-pages-causes-crash">this
Connect issue</a>, it's a limitation of the platform that the Frame object can't serialize
complex objects. The workaround is to only pass around the unique identifiers as it
is demonstrated in both above mentioned Visual Studio templates. If you don't mind
reloading your data every time a new page is loaded, that's not a problem. Otherwise
you need to cache your data in memory.
</p>
        <p>
Both templates contain only sample data and cache it in a static member. Unfortunately
static members don't lend themselves well to the MVVM pattern and testing therefore
it's a better idea to inject the application state into the view models. I like the
following approach using the view model locator pattern:
</p>
        <pre class="brush: csharp;">public class ViewModelLocator
{
    private static ApplicationState applicationState;

    static ViewModelLocator()
    {
        applicationState = new ApplicationState();
    }

    public ViewModel ViewModel
    {
        get
        {
            return new ViewModel(applicationState);
        }
    }
}

</pre>
        <p>
The code can be improved further by using an IoC container which will ensure a single
instance of the application state even without having a static reference to it in
the view model locator as long as you scope it properly. But that's already a subject
for another post.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=e4fa2f50-2ef0-471e-b0f3-c8d2e00e3c83" />
      </body>
      <title>Using SuspensionManager for Saving Application State</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,e4fa2f50-2ef0-471e-b0f3-c8d2e00e3c83.aspx</guid>
      <link>http://www.damirscorner.com/UsingSuspensionManagerForSavingApplicationState.aspx</link>
      <pubDate>Sun, 23 Sep 2012 17:50:28 GMT</pubDate>
      <description>&lt;p&gt;
One of the important aspects of Windows Store application development is the application
lifecycle. While at first it might seem a minor detail that can be taken care of late
in the application development process, it can affect the application architecture
quite profoundly. Therefore it's a good idea to address it soon enough to avoid unplanned
refactoring when the application is almost complete.
&lt;/p&gt;
&lt;p&gt;
&lt;img title="Windows Store application lifecycle" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Windows Store application lifecycle" src="http://www.damirscorner.com/content/binary/Windows-Live-Writer/0fbdec84f825_115F2/clip_image001_3.png" width="615" height="293"&gt;
&lt;/p&gt;
&lt;p&gt;
Since the basics of Windows Store application lifecycle are &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx"&gt;well
documented&lt;/a&gt;, I'm not going to repeat them here. Rather, I'm going to focus on a
single aspect of it: the transition between the running and the suspended state. During
this transition the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.application.suspending%28v=win.10%29.aspx"&gt;Application.Suspending&lt;/a&gt; event
is called to allow the application to save its state to local storage which can be
used to resume the application in case it gets terminated.
&lt;/p&gt;
&lt;p&gt;
If you base your application on correct templates for Windows Store applications which
are included with Visual Studio 2012 this will already be mostly taken care of for
you. Both Grid App and Split App templates include a SuspensionManager class in their
Common folder and also call it at all the appropriate spots in the application. This
class can save the application state to the local storage into a file named _sessionState.xml
and later reload it. It includes the complete frame navigation history consisting
of the loaded pages and the parameters they were loaded with. As long as you only
need this parameter to completely restore the state of the page, you don't have to
do anything extra.
&lt;/p&gt;
&lt;p&gt;
&lt;img title="Debug Location toolbar in Visual Studio 2012" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Debug Location toolbar in Visual Studio 2012" src="http://www.damirscorner.com/content/binary/Windows-Live-Writer/0fbdec84f825_115F2/clip_image002_3.png" width="624" height="104"&gt;
&lt;/p&gt;
&lt;p&gt;
There's &lt;a href="http://blogs.msdn.com/b/visualstudio/archive/2012/08/23/new-visual-studio-2012-debugging-features-for-the-windows-8-app-lifecycle-model.aspx"&gt;a
function in Visual Studio&lt;/a&gt; that makes it easy to test that, it's just hidden in
its default configuration. To access it you first need to show the Debug Location
toolbar. There is a dropdown menu on it which is enabled only when the application
is running. It contains three items: Suspend, Resume, and Suspend and shutdown. The
last one is your friend when you want to test how your application resumes after it
has been terminated: just run the application, navigate to the page you want to test
and invoke the Suspend and shutdown action. The next time you run the application,
it should resume with the same state.
&lt;/p&gt;
&lt;p&gt;
Unfortunately you can easily break suspending and resuming in your application if
you pass a custom class as the page parameter. Try it out! For example you can replace
the UniqueId that's being passed between the GroupedItemsPage and GroupDetailPage
in the Grid App template with a complete instance of SampleDataGroup. If you now Suspend
and shutdown your application, the SuspensionManager.SaveAsync method will throw a
non-descriptive SuspensionManagerException: "SuspensionManager failed". Investigating
the call stack reveals that the failing method was actually &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.frame.getnavigationstate%28v=win.10%29.aspx"&gt;Frame.GetNavigationState&lt;/a&gt; which
has thrown an easier to comprehend COMException (It sounds like an oxymoron, doesn't
it?): "WinRT information: GetNavigationState doesn't support serialization of a parameter
type which was passed to Frame.Navigate.".
&lt;/p&gt;
&lt;p&gt;
What can we do about it? As it turns out, not much. According to &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/753331/xaml-metro-app-complex-objects-as-parameter-when-navigating-between-pages-causes-crash"&gt;this
Connect issue&lt;/a&gt;, it's a limitation of the platform that the Frame object can't serialize
complex objects. The workaround is to only pass around the unique identifiers as it
is demonstrated in both above mentioned Visual Studio templates. If you don't mind
reloading your data every time a new page is loaded, that's not a problem. Otherwise
you need to cache your data in memory.
&lt;/p&gt;
&lt;p&gt;
Both templates contain only sample data and cache it in a static member. Unfortunately
static members don't lend themselves well to the MVVM pattern and testing therefore
it's a better idea to inject the application state into the view models. I like the
following approach using the view model locator pattern:
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public class ViewModelLocator
{
    private static ApplicationState applicationState;

    static ViewModelLocator()
    {
        applicationState = new ApplicationState();
    }

    public ViewModel ViewModel
    {
        get
        {
            return new ViewModel(applicationState);
        }
    }
}

&lt;/pre&gt;
&lt;p&gt;
The code can be improved further by using an IoC container which will ensure a single
instance of the application state even without having a static reference to it in
the view model locator as long as you scope it properly. But that's already a subject
for another post.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=e4fa2f50-2ef0-471e-b0f3-c8d2e00e3c83" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,e4fa2f50-2ef0-471e-b0f3-c8d2e00e3c83.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/C#</category>
      <category>Development/Metro</category>
      <category>Development/Windows Store</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=b60c0955-c86d-48a5-9d30-1cb6e117db51</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,b60c0955-c86d-48a5-9d30-1cb6e117db51.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,b60c0955-c86d-48a5-9d30-1cb6e117db51.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b60c0955-c86d-48a5-9d30-1cb6e117db51</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The lifecycle of Metro style apps requires them to save their state when they are
being suspended by the OS to prevent the potential loss of their state if they are
restarted instead of resumed because they were inactive for two long.
</p>
        <p>
The basic pattern of doing this is pretty simple. When the app is being suspended
an event is raised by its Application class. The application state can be saved inside
the event handler attached to it:
</p>
        <pre class="brush: csharp;">sealed partial class App : Application
{
    public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;
    }

    private async void OnSuspending(object sender, SuspendingEventArgs e)
    {
        // do your work here
    }
}

</pre>
        <p>
By inspecting the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.suspendingeventargs.aspx">SuspendingEventArgs</a> passed
to the handler you can see there’s a deadline for completing the operation. The following
snippet can be used to see how much time you actually have available:
</p>
        <pre class="brush: csharp;">private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    Debug.WriteLine(e.SuspendingOperation.Deadline - DateTime.Now);
}

</pre>
        <p>
The output will constantly be approximately 5 seconds. That’s the amount of time the
OS gives the application to save its state before it forcibly stops the process. If
you try running the following piece of code you might be in for a surprise, though:
</p>
        <pre class="brush: csharp;">private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    await Task.Delay(1000);
    Debug.WriteLine("Done");
}

</pre>
        <p>
There will be no output in this case. It turns out that if you want to take advantage
of all the time available, you need to tell that to the OS otherwise it will stop
you well before the time runs out. There’s only a minor modification of the code above
required:
</p>
        <pre class="brush: csharp;">private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    var deferral = e.SuspendingOperation.GetDeferral();
    try
    {
        await Task.Delay(1000);
        Debug.WriteLine("Done");
    }
    finally
    {
        deferral.Complete();
    }
}

</pre>
        <p>
Of course, you still need to be done before reaching the deadline, otherwise the OS
will step in anyway.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=b60c0955-c86d-48a5-9d30-1cb6e117db51" />
      </body>
      <title>Saving State in a Suspending Metro Style App</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,b60c0955-c86d-48a5-9d30-1cb6e117db51.aspx</guid>
      <link>http://www.damirscorner.com/SavingStateInASuspendingMetroStyleApp.aspx</link>
      <pubDate>Wed, 04 Jul 2012 18:55:04 GMT</pubDate>
      <description>&lt;p&gt;
The lifecycle of Metro style apps requires them to save their state when they are
being suspended by the OS to prevent the potential loss of their state if they are
restarted instead of resumed because they were inactive for two long.
&lt;/p&gt;
&lt;p&gt;
The basic pattern of doing this is pretty simple. When the app is being suspended
an event is raised by its Application class. The application state can be saved inside
the event handler attached to it:
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;sealed partial class App : Application
{
    public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;
    }

    private async void OnSuspending(object sender, SuspendingEventArgs e)
    {
        // do your work here
    }
}

&lt;/pre&gt;
&lt;p&gt;
By inspecting the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.suspendingeventargs.aspx"&gt;SuspendingEventArgs&lt;/a&gt; passed
to the handler you can see there’s a deadline for completing the operation. The following
snippet can be used to see how much time you actually have available:
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    Debug.WriteLine(e.SuspendingOperation.Deadline - DateTime.Now);
}

&lt;/pre&gt;
&lt;p&gt;
The output will constantly be approximately 5 seconds. That’s the amount of time the
OS gives the application to save its state before it forcibly stops the process. If
you try running the following piece of code you might be in for a surprise, though:
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    await Task.Delay(1000);
    Debug.WriteLine("Done");
}

&lt;/pre&gt;
&lt;p&gt;
There will be no output in this case. It turns out that if you want to take advantage
of all the time available, you need to tell that to the OS otherwise it will stop
you well before the time runs out. There’s only a minor modification of the code above
required:
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;private async void OnSuspending(object sender, SuspendingEventArgs e)
{
    var deferral = e.SuspendingOperation.GetDeferral();
    try
    {
        await Task.Delay(1000);
        Debug.WriteLine("Done");
    }
    finally
    {
        deferral.Complete();
    }
}

&lt;/pre&gt;
&lt;p&gt;
Of course, you still need to be done before reaching the deadline, otherwise the OS
will step in anyway.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=b60c0955-c86d-48a5-9d30-1cb6e117db51" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,b60c0955-c86d-48a5-9d30-1cb6e117db51.aspx</comments>
      <category>Development</category>
      <category>Development/.NET</category>
      <category>Development/Metro</category>
      <category>Development/Windows Store</category>
    </item>
  </channel>
</rss>