GetClickedElement returns null within a Dispatcher.BeginInvoke code section

6 posts, 0 answers
  1. Paul Brun
    Paul Brun avatar
    41 posts
    Member since:
    May 2010

    Posted 20 Sep 2011 Link to this post

    I have a method that renames a tree element. 

    private void RenameAction()
    {
       if (this.ClickedTreeViewItem != null)
       {
         Dispatcher.BeginInvoke(() =>
         {
           this.ClickedTreeViewItem.BeginEdit();
         });
       }
       else
       {
         Dispatcher.BeginInvoke(() =>
         {
            this.m_SelectedContextEntity.BeginEdit();
         });
       }
    }

    ClickTreeViewItem is a property in my class that returns the element that is clicked via the "GetClickElement<T>" call.

    The check confirms that the clicked element is not null, but the same property within the dispatcher section returns null. The Dispatcher allows us to run the method on the UI Main thread.

    Any thoughts on why this would be happening? 
    Thanks
    Paul

  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 26 Sep 2011 Link to this post

    Hello Paul Brun,

    Apparently the clicked element is null in the dispatcher because the check is executed in different timeframe than the check in the upper if. You could assign the return value of the function call to a local variable and use that variable for checks and later operations in the method.

    Hope this helps. Please let us know if you have further concerns.

    Greetings,
    Hristo
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. Paul Brun
    Paul Brun avatar
    41 posts
    Member since:
    May 2010

    Posted 26 Sep 2011 Link to this post

    Thanks for the suggestion. I have implemented that, was just curious why it worked in a previous release and not the current one. Or, was it just luck that it worked??? Regards, Paul
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 29 Sep 2011 Link to this post

    Hello Paul Brun,

     Probably it is not the release version and it is the inconsistent (due to the asynchronous work) behavior of the Disaptcher. What are the two release versions that you compare?

    All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Paul Brun
    Paul Brun avatar
    41 posts
    Member since:
    May 2010

    Posted 29 Sep 2011 Link to this post

    The two versions of the Telerik Controls I compared were:

    2011.2 712 vs. 2010.3 1314

    Cheers,
    Paul
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 04 Oct 2011 Link to this post

    Hi Paul Brun,

     You could also try the Q2 2011 SP1 (0920) version of RadControls but still, we think that it is more like a "Dispatcher-timing" result than a change in the RadTreeView from Q1 SP1 to Q2. Feel free to ask if you have further questions.

    Kind regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner