3

I really need some code examples here... What I am trying to do:

GetCollectionFromDatabase
foreach item
{
    resetEvents[i] = new ManualResetEvent(false);
    var makeRequest = new MakeRequest(resetEvents[i]);

    ThreadPool.QueueUserWorkItem(new WaitCallback(makeRequest.ThreadPoolCallback), i);
}
db.Save();

ThreadPoolCallback    
{
    update/delete the row 
}

Is this the right appoach? Do I pass in the db as a ref to the ThreadPoolCallBack?

1 Answer 1

1

You will have to create a context within the thread pool callback. Entity framework contexts are not multi threaded and cannot be shared by different threads.

I take it db is your database context in this case. You will have to create a new one in ThreadPoolCallback and save it there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.