Print Page | Close Window

PropertyChanged not firing

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3281
Printed Date: 25-Mar-2025 at 1:01am


Topic: PropertyChanged not firing
Posted By: samir
Subject: PropertyChanged not firing
Date 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



Replies:
Posted By: DenisK
Date 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.


Posted By: samir
Date 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?

 



Posted By: DenisK
Date 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 - 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 - 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.



Print Page | Close Window