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 8696579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:18:23+00:00 2026-06-13T01:18:23+00:00

the rest of our team and me created a Silverlight application. We’ve been using

  • 0

the rest of our team and me created a Silverlight application. We’ve been using .NET 4.0. Though we already put the async/await pattern into our application (Microsoft.CompilerServices.AsyncTargetingPack.Net4).

Now that MS won’t put too much additional effort into Silverlight, we just thought, that we build a little HTML5/JS application – just for experimenting issues.

So… I tried to bootstrap the application, like we did in the previous SL app. I’m using a class library, which is used in our main application, to provide all the data. To fill all the dictionaries in our context, we call some asynchronous methods, to retrieve the data from the DB. I’d like to use this lib in the MVC app, either, but I can’t call those async methods, because Application_Start in Global.asax isn’t async.

How to achieve this?

Alternating the library isn’t a viable solution, because it’s used in production code. Writing a new lib won’t be a solution, too, because we’d really like to keep maintenance as small as possible.

Any suggestions?

  • 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-13T01:18:24+00:00Added an answer on June 13, 2026 at 1:18 am

    I recommend you start the asynchronous loading in Application_Start, and then await for it to complete in your MVC actions.

    You can do this easily by saving the Task<Dictionary<..>> into a static variable and then having each asynchronous action await it.

    // Or in a repository or whatever...
    public static class SharedData
    {
      public static Task<Dictionary<int, string>> MyDictionary;
    }
    
    ...
    
    Application_Start(..)
    {
      // Start the dictionary filling, but don't wait for it to complete.
      // Note that we're saving the Task, not await'ing it.
      MyDictionary = MyLibrary.GetDictionary();
    }
    

    Then in each asynchronous action that needs it:

    public async Task<ActionResult> Get()
    {
      // Asynchronously wait for the dictionary to load if it hasn't already.
      var dict = await SharedData.MyDictionary;
      ...
      return View();
    }
    

    Alternatively, you can use asynchronous lazy initialization for this. Asynchronous lazy initialization was first publicized by Stephen Toub; I documented the code and upgraded it to .NET 4.5 on my blog, and recently added it to my AsyncEx library.

    Using AsyncLazy<T>, your code would look like this:

    // Or in a repository or whatever...
    public static class SharedData
    {
      public static AsyncLazy<Dictionary<int, string>> MyDictionary =
          new AsyncLazy<Dictionary<int, string>>(async () =>
          {
            var ret = new Dictionary<int, string>();
            await MyLibrary.FillDictionary(ret);
            return ret;
          });
    }
    

    Then in each asynchronous action that needs it:

    public async Task<ActionResult> Get()
    {
      // Asynchronously wait for the dictionary to load if it hasn't already.
      var dict = await SharedData.MyDictionary;
      ...
      return View();
    }
    

    Asynchronous lazy initialization has the capability to be lazy, so the first action needing a specific dictionary will await it. If there are dictionaries that aren’t used, then they’ll never be loaded.

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

Sidebar

Related Questions

My team wants to begin a trial run of using Mercurial on our existing
In our application, some of our REST-style WCF calls are failing. These calls are
So someone on our team was using TortoiseSVN and made some ten commitments in
Our team is developing our first web api and using Service Stack to expose
Im building api for our rest api using ASIHTTPRequest. Api wraps all requests to
We are currently using a Jersey JAX-RS implementation to handle our REST requests (server-side
We've to implement a REST API to access some features of our current server,
I am creating a site for our customer service department to request password rest
I'm building a REST application with AppEngine Datastore as persistence layer. However I have
I have a REST API using Django Tastypie. Given the following code The models

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.