New Posts New Posts RSS Feed: Possible EntityManager Threading bug?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Possible EntityManager Threading bug?

 Post Reply Post Reply
Author
tersiusk View Drop Down
Newbie
Newbie
Avatar

Joined: 03-Nov-2010
Posts: 20
Post Options Post Options   Quote tersiusk Quote  Post ReplyReply Direct Link To This Post Topic: Possible EntityManager Threading bug?
    Posted: 03-Nov-2010 at 7:18am
Hi

I perform an async query but the entity manager throws an exception because the thread id's don't match. By setting the AuthorizedThreadId to null the exceptions stop. I'm just wondering should AuthorizedThreadId be set to null in these cases or is something else going on?

EntityManager entityManager = new EntityManager();
entityManager.AuthorizedThreadId = null;

var userQuery = entityManager.GetQuery<User>().Where(u => u.Username.ToLower() == valuetoverify.ToString());

userQuery.ExecuteAsync((u) =>
{
    var results = u.Results;
});


Edited by tersiusk - 03-Nov-2010 at 7:19am
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2010 at 8:45am
You shouldn't see a problem with the above in a Silverlight application (or even WPF or WinForms if you want to do async there), but in free threading environments which don't synchronize a callback to the same thread you will see the issue.  These environments would include a console application, unit test environments, and ASP.NET.  If you do want to do async in these environments then setting the AuthorizedThreadId is required in order to avoid the exception.  If you are running in a synchronized threading environment and seeing the error, it does mean that the EntityManager, which is not thread-safe, is being used on multiple threads.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down