New Posts New Posts RSS Feed: PropertyChanged not firing
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

PropertyChanged not firing

 Post Reply Post Reply
Author
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Topic: PropertyChanged not firing
    Posted: 23-Feb-2012 at 6:09pm
Hi samir,

I don't claim to know exactly what's going on but I do know that the EntityManager is not thread-safe. See http://drc.ideablade.com/xwiki/bin/view/Documentation/entitymanager-not-thread-safe.

In general, we don't recommend that you work with multiple threads when using the EntityManager.

If you have a need to batch asynchronous queries, you can try DevForce Coroutines. See http://drc.ideablade.com/xwiki/bin/view/Documentation/coroutines

My suggestion for now is to convert your first 4 queries to use Coroutines instead of Task and see if you're still experiencing the same issue.

Hope this helps.
Back to Top
samir View Drop Down
Newbie
Newbie


Joined: 30-Mar-2011
Posts: 14
Post Options Post Options   Quote samir Quote  Post ReplyReply Direct Link To This Post Posted: 23-Feb-2012 at 5:56am

Hi Denis,

Here it is:

         var taskSistema = DataRepository.ExecuteQueryTaskAsync(DataRepository.GetQuery<Sistema>());

         taskSistema.Wait();

 

         var taskRevendas = DataRepository.ExecuteQueryTaskAsync(DataRepository.GetQuery<Revenda>());

         taskRevendas.Wait();

 

         var taskFornecedores = DataRepository.ExecuteQueryTaskAsync(DataRepository.GetQuery<Fornecedor>());

         taskFornecedores.Wait();

 

         var taskTransportadoras = DataRepository.ExecuteQueryTaskAsync(DataRepository.GetQuery<Transportadora>());

         taskTransportadoras.Wait();

 

And the respective DataRepository methods:

 

        public IQueryable<T> GetQuery<T>() where T : Entity

        {

            return Manager.GetQuery<T>();

        }

        public Task<List<T>> ExecuteQueryTaskAsync<T>(IQueryable<T> query) where T : Entity

        {

            var tcs = new TaskCompletionSource<List<T>>();

 

            Task.Factory.StartNew(() =>

                                      {

                                          Manager.ExecuteQueryAsync((EntityQuery<T>) query, operation =>

                                                                                                {

 

                                                                                                    if (operation.CompletedSuccessfully)

                                                                                                        tcs.SetResult(operation.Results.ToList());

                                                                                                    else

                                                                                                    {

                                                                                                        operation.MarkErrorAsHandled();

                                                                                                        tcs.SetException(operation.Error);

                                                                                                    }

                                                                                                });

                                      });

            return tcs.Task;

        }

Examining the code I now see that the Manager.ExecuteQueryAsync doesn´t need to be inside the Task.Factory.StartNew. So I made the change but the issue is still present. Any ideas?

 

Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 22-Feb-2012 at 2:37pm
Hi Samir,

This sounds like a threading issue. Could you provide me with a code snippet of the 4 parallel queries?

Thanks.
Back to Top
samir View Drop Down
Newbie
Newbie


Joined: 30-Mar-2011
Posts: 14
Post Options Post Options   Quote samir Quote  Post ReplyReply Direct Link To This Post Posted: 21-Feb-2012 at 1:57pm
Hello.
 
I´m having a situation where sometimes when I run my application my entities don´t fire the PropertyChanged event after startup. Investigating the issue with Reflector I discovered that the method QueueEvent(Action action) in the EntityGroup class is called with an action to raise the event, but due to EntityManager.IsLoadingEntity being true, the action gets queued and never executes.
 
It seems IsLoadingEntity is set to true in the constructor of LoadingBlock and the original value is restored when this object is disposed.
 
As I have about 4 parallel queries running in my application startup, I believe that one LoadingBlock is being instantiated after a previous LoadingBlock had set EntityManager.IsLoadingEntity to true but have not been disposed yet, thus this if this new LoadingBlock ends after the first, it sets IsLoadingEntity to true and it remains true forever.
 
PS: I´ve checked that every LoadingBlock instantiated is being disposed.
 
Does any of this make sense?
 
Thanks,
Samir Zattar


Edited by samir - 21-Feb-2012 at 2:02pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down