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

  • Home
  • SEARCH
  • 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 9217845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:43:27+00:00 2026-06-18T02:43:27+00:00

I am developing a heavy MVC routine that will delay some minutes to process.

  • 0

I am developing a heavy MVC routine that will delay some minutes to process. Then I call an Ajax request and I would like to send an answer from controller to interface if the process has started correctly and to keep executing it using a Thread. However, when the return is sent, it is needed to access the database, and I have the following error: Object disposed.

My code:

var entidade = this._repositorioDeTabelaDePremiacaoUPL.ObterPorID(dto.ID);
if(entidade.StatusDoServico == ListaDeStatusDoServico.tcProcessando.Id)
     return Content("{success:false}");

Thread thread = new Thread(() => this._servicoDeTabelaDePremiacaoUPL.GerarTabela(dto));
thread.Start();
GerenciadorDeUnidadeDeTrabalho.Corrente.Commit();

return Content("{success:true}");
  • 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-18T02:43:28+00:00Added an answer on June 18, 2026 at 2:43 am

    I suggest to use an extra db context for your thread and dispose it at the end. Because your db context for your web application and extra thread have different lifecycles. For web application it is generealy per HttpContext – web request and for thread is it the lifespan of the thread. You can create new instance of your db context at own or use some Conditional object construction.

    Notes:

    It is not a very good practice to reuse your db context for whole lifecycle of your application and reference it as static property (it could lead in concurrency issues and the entities state inside the context could become inconsistent). Better approach is to register your db context in HTTPContext scope (InstanceScope.HttpContext) and then use constructor injection on your controllers.

    Global.asax

    ObjectFactory.Configure(i => { i.For<ContextoBase>().LifecycleIs(Lifecycles.GetLifecycle(InstanceScope.HttpContext)).Use<ContextoDaAplicacao>(); }
    

    Controller

    public MyController(ContextoBase context){
        this.context = context;
    }
    // then use it in action methods (note: it will be automatically disposed at the end of the web request)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an ajax heavy web app, and would like to have textarea 's
I’m currently developing an application that will be heavy on images, that I hope
I'm developing a CodeIgniter based site that will be very multi language heavy. Plan
I'm developing an AJAX-heavy site with JavaScript MVC and an ASP.NET MVC server. To
I am developing a cocoa application that will be making heavy use of both
I'm developing an application that makes heavy use of web services. I will be
I'm developing a heavy AJAX Symfony 2 app. Most of my actions begin this
Ok so I'm developing a WPF application that makes heavy use of SQL Server.
I am developing a application with asp.net 4.0. My site will be a heavy
I am developing a website that has some sort of realtime update. Now the

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.