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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:13:35+00:00 2026-05-31T16:13:35+00:00

Hello i’m trying to implement an AsynController, here is my code: [NoCache] public class

  • 0

Hello i’m trying to implement an AsynController,

here is my code:

[NoCache]
public class GraphController : BaseAsyncController
{
    private readonly IReportsRepository _reportsRepository;
    private readonly ISqlQueryRepository _sqlQueryRepository;

    //Background worker
    private readonly BackgroundWorker _worker = new BackgroundWorker();

    public GraphController(ISqlQueryRepository sqlQueryRepository, IReportsRepository reportsRepository)
    {
        _sqlQueryRepository = sqlQueryRepository;
        _reportsRepository = reportsRepository;
    }

    public void Index()
    {
        AsyncManager.OutstandingOperations.Increment();

        _worker.DoWork += (sender, args) =>
        {
            AsyncManager.Parameters["message"] = "hello world";
            Thread.Sleep(3000);
        };

        _worker.RunWorkerCompleted += (sender, args) => AsyncManager.OutstandingOperations.Decrement();
        //run the worker
        _worker.RunWorkerAsync();
    }

    public ActionResult IndexCompleted(string message) //callback not being invoked
    {
        ViewData["message"] = message;
        return View();
    }
}

The question is why the completed callback is not being invoked?

Thanks in advance.

  • 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-05-31T16:13:37+00:00Added an answer on May 31, 2026 at 4:13 pm

    The name of your action is wrong. It should not be Index. It should be IndexAsync. Take a look at the following article which illustrates the usage of asynchronous controllers in ASP.NET MVC.

    Note that BackgroundWorker is a Windows Form component. Don’t use WinForms components in ASP.NET applications. They are not designed to be used in server applications. I’d recommend you TPL.

    So:

    [NoCache]
    public class GraphController : BaseAsyncController
    {
        private readonly IReportsRepository _reportsRepository;
        private readonly ISqlQueryRepository _sqlQueryRepository;
    
        public GraphController(ISqlQueryRepository sqlQueryRepository, IReportsRepository reportsRepository)
        {
            _sqlQueryRepository = sqlQueryRepository;
            _reportsRepository = reportsRepository;
        }
    
        public void IndexAsync()
        {
            AsyncManager.OutstandingOperations.Increment();
            Task.Factory.StartNew(() => 
            {
                // do the work
                Thread.Sleep(3000);
    
                // the work is finished => pass the results and decrement
                AsyncManager.Parameters["message"] = "hello world";
                AsyncManager.OutstandingOperations.Decrement();
            });
        }
    
        public ActionResult IndexCompleted(string message)
        {
            ViewData["message"] = message;
            return View();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am trying to do a SOAP request here is my code: #
Hello I am trying to create a stacked barplot using the following code: test
Hello friends here's my code function dropItems(idOfDraggedItem,targetId,x,y) { var html = document.getElementById('dropContent').innerHTML; if(html.length<=0){ html.innerHTML='<img
Hello can anybody solve this please I'm creating the object in the action class
Hello everyone i am trying to format the input number range with php number_format
hello friends i am trying to get a list of user id and want
Hello Guys I am trying to figure out why i am gettings this error
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =
Hello All I am trying to flatten a list in Ocaml. I am a
Hello i been trying to get a tokenizer to work using the boost library

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.