Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:27:22+00:00 2026-06-08T03:27:22+00:00

I have been experimenting a lot lately with Windows 8, writing C# XAML Metro

  • 0

I have been experimenting a lot lately with Windows 8, writing C# XAML Metro style apps using WinRT components written in C++/CX for better performance and to use functionality not available in C#, specifically DirectX.

While loading resources from my app package in my WinRT component, my app threw the following:

Unhandled exception at 0x0fd58ae3 (MSVCR110D.dll) in TestResources.exe: 0xC0000409: 0xc0000409.

I was trying to make asynchronous calls to the new StorageFile API (Windows::Storage::StorageFile::GetFileFromApplicationUriAsync chained to other calls for reading the file contents) and synchronize the resulting task chain using concurrency::task.get().

It didn’t seem to be working. If I didn’t call concurrency::task.get() or concurrency::task.wait(), then the problem did not occur, but I needed the result synchronously because of how my DirectX code was written.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:27:24+00:00Added an answer on June 8, 2026 at 3:27 am

    The reason is that you are calling concurrency::task.wait() or concurrency::task.get() from the UI thread! The framework throws an exception to prevent you from freezing the app. See: Creating Asynchronous Operations in C++ for Metro style Apps, toward the bottom there are three warnings. The last warning says:

    Do not call concurrency::task::wait in the body of a continuation that runs on the STA. Otherwise, the runtime throws concurrency::invalid_operation because this method blocks the current thread and can cause the app to become unresponsive.

    I wrote a test app and verified that I could make everything work by calling my WinRT component from a separate thread!

    Details below:

    My test app is C# XAML Metro app calling WinRT component to load a string from a file. It has a Button and a TextBlock.

    The resource loader looks like this:

    class WstringCaselessLess : std::binary_function< std::wstring, std::wstring, bool >
    {
    public:
        bool operator()( const std::wstring& s1, const std::wstring& s2 )
        {
            return _wcsicmp( s1.c_str(), s2.c_str() ) < 0;
        }
    };
    
    public ref class ComponentResourceLoader sealed
    {
    public:
        Platform::String^ GetStringResource( Platform::String^ uri )
        {
            auto key = std::wstring( uri->Data(), uri->Length() );
            auto findit = m_resourceMap.find( key );
            if ( findit != std::end( m_resourceMap ) )
                return ref new Platform::String( findit->second.c_str() );
            auto uriObj = ref new Windows::Foundation::Uri( uri );
            auto fileOp = Windows::Storage::StorageFile::GetFileFromApplicationUriAsync( uriObj );
            return concurrency::create_task( fileOp )
                    .then( [this, &key]( Windows::Storage::StorageFile^ file )
                           -> Windows::Foundation::IAsyncOperation< Windows::Storage::Streams::IBuffer^ >^
                        {
                            return Windows::Storage::FileIO::ReadBufferAsync( file );
                        } )
                    .then( [this, &key]( Windows::Storage::Streams::IBuffer^ buffer )
                           -> Platform::String^
                        {
                            auto reader = Windows::Storage::Streams::DataReader::FromBuffer( buffer );
                            auto str = reader->ReadString( buffer->Length );
                            this->m_resourceMap[key] = std::wstring( str->Data(), str->Length() );
                            return str;
                        } ).get();
        }
    private:
        std::map< std::wstring, std::wstring, WstringCaselessLess > m_resourceMap;
    };
    

    The broken button click handler looks like this:

    private void WinRT_Click_1(object sender, RoutedEventArgs e)
    {
        TextContent.Text = m_loader.GetStringResource(@"ms-appx:///Assets/Hello.xml");
    }
    

    If I change the button handler to load the string in a separate thread, it works:

    private async void WinRT_Click_1(object sender, RoutedEventArgs e)
    {
        var text = await Task.Run<string>(() => RunWinrtLoader());
        TextContent.Text = text;
    }
    private string RunWinrtLoader()
    {
        return m_loader.GetStringResource(@"ms-appx:///Assets/Hello.xml");
    }
    

    Hope this is helpful to someone! It sure had me pretty angry for a while, because there is no indication from the error to the real problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been experimenting with a lot of web development apps like Drupal, Moodle,
I have been experimenting with sending messages from two .NET Windows Forms applications using
I have been experimenting a lot lately with different technologies for drawing 2D-sprites on
I have been experimenting with writing applications that use a local SQL Database to
I have been experimenting recently with Silverlight, RIA Services, and Entity Framework using .NET
I have been experimenting a lot with some glassy images, such as the one
I have been experimenting using a Facebook login button on my website. The login
I have been experimenting with geography datatype lately and just love it. But I
I have been experimenting with capturing click events outside of elements using stopPropagation() .
I have been experimenting with making GUIs in java as opposed to just using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.