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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:41:31+00:00 2026-06-09T20:41:31+00:00

I am getting the error below when running a query in Entity Framework 4.3

  • 0

I am getting the error below when running a query in Entity Framework 4.3 in a thread.

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

Below is where my thread starts and it errors at var item = _gamesRepository.Get(gameIncludes, q => q.Id == gameId);. Am I doing something wrong or should I use a different approach?

public void ProcessGame(int gameId)
        {
            new Thread(() =>
            {
                Expression<Func<Game, object>>[] gameIncludes = {
                                                                q => q.DivisionGameTeamResults,
                                                                q => q.DivisionGameTeamResults.Select(g => g.DivisionBracketGameParticipant),
                                                                q => q.DivisionGameTeamResults.Select(g => g.DivisionTeamPoolGame),
                                                                q => q.DivisionGameTeamResults.Select(g => g.DivisionTeamPoolGame.DivisionTeamPool),
                                                                e => e.DivisionGameTeamResults.Select(q => q.DivisionBracketGameParticipant.DivisionBracketGame.DivisionBracketGameParticipants.Select(t => t.DivisionBracketGameParticipantTeam.DivisionTeam.Team)),
                                                                e => e.DivisionGameTeamResults.Select(q => q.DivisionBracketGameParticipant.DivisionBracketGame.DivisionLoserBracketGameParticipants.Select(d => d.DivisionBracketGameParticipantPool.DivisionPool)),
                                                                e => e.DivisionGameTeamResults.Select(q => q.DivisionBracketGameParticipant.DivisionBracketGame.DivisionLoserBracketGameParticipants.Select(d => d.DivisionBracketGameParticipantTeamPool.DivisionTeamPool.DivisionTeam)),
                                                                q => q.DivisionGameTeamResults.Select(d => d.DivisionTeamPoolGame.DivisionTeamPool.DivisionPool.Division.Event.Members),
                                                                q => q.DivisionGameTeamResults.Select(d => d.DivisionBracketGameParticipant.DivisionBracketGame.BracketPart.DivisionBracketPart.DivisionBracket.Division.Event.Members)
                                                            };
                var item = _gamesRepository.Get(gameIncludes, q => q.Id == gameId);

                if (item != null)
                {
                    if (item.DivisionGameTeamResults.All(d => d.DivisionTeamPoolGame != null))
                    {
                        // Pool Game
                        _divisionBracketsService.ProcessPoolGame(item);
                    }
                    else if (item.DivisionGameTeamResults.All(d => d.DivisionBracketGameParticipant != null))
                    {
                        // Bracket Game
                        _divisionBracketsService.ProcessBracketGame(item);
                    }

                    UnitOfWork.Commit();
                }

            }).Start();
        }

UPDATE:

I made the required changes to fix that issue.

var gamesRepository = DependencyResolver.Current.GetService<IGamesRepository>();
var divisionBracketsService = DependencyResolver.Current.GetService<IDivisionBracketsService>();
  • 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-09T20:41:32+00:00Added an answer on June 9, 2026 at 8:41 pm

    Repository and unit of work should be owned by your thread for two reasons:

    • EF is not thread safe – sharing context among threads can lead you to false belief that you can do concurrent operations on the same context instance but you in general can’t. This may change in EF6 where async support will be implemented but current version is only for single threaded processing.
    • If you share context between threads you must ensure that the thread owning the context does not dispose the context before any other thread dependent on that context finishes its processing – that is your current problem. It means that your calling thread should wait on your processing thread to complete.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while running: rake snorby:setup getting below error: rake aborted! You have already activated rake
When running IIS, I'm getting the below error on all ASPX pages. ASP.NET is
I am getting below error when running a target of ANT script. Error message
I am getting the below error when running my deployed app. Going by the
I'm running kmeans on a large dataset and I'm always getting the error below:
I'm getting the below error while running the below script. My goal is to
I am getting below error while running gzip command over ssh ssh 123@HPUX gzip
I was getting the below error when running scripts Problem while capturing system stateundefined
I'm getting the below error in a Magento PHP file running a CREATE TABLE
I am getting the error below when I call my WCF service. What am

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.