{"id":3616,"date":"2014-03-29T06:55:16","date_gmt":"2014-03-29T06:55:16","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/setting-datacontext-to-null-in-destructor-collection-of-common-programming-errors\/"},"modified":"2014-03-29T06:55:16","modified_gmt":"2014-03-29T06:55:16","slug":"setting-datacontext-to-null-in-destructor-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/setting-datacontext-to-null-in-destructor-collection-of-common-programming-errors\/","title":{"rendered":"Setting DataContext to Null in Destructor-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to set the DataContext of a PhoneApplicationPage to Null in Destructor. But this throws Invalid Cross Thread Exception. I want to dispose my datacontext when the page is no longer in use. i.e. if user navigates from Page1 to Page2 and then goes back to Page1, I want to dispose Page2 as well as its datacontext. I&#8217;m facing 2 issues in this case.\u00a0<\/p>\n<p>1. If i have interaction triggers in Page2, destructor of Page2 is not getting called when we go back to Page1. This issue is already posted by someone in the below link.\u00a0<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"JCpZvWNxNs\"><p><a href=\"https:\/\/sartorialsolutions.wordpress.com\/2010\/10\/01\/60\/\">Memory leak using Interaction Triggers on loaded event with MVVM&nbsp;light<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Memory leak using Interaction Triggers on loaded event with MVVM&nbsp;light&#8221; &#8212; Simon Ransom&#039;s space\" src=\"https:\/\/sartorialsolutions.wordpress.com\/2010\/10\/01\/60\/embed\/#?secret=17eYaaH9as#?secret=JCpZvWNxNs\" data-secret=\"JCpZvWNxNs\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>2. If I remove these interaction triggers in Page2, destructor of Page2 is getting called, but destructor of my dataContext is not executed. I tried setting this.datacontext = null in Page2 and got Invalid Cross thread exception.\u00a0<\/p>\n<p>Any suggestions?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to set the DataContext of a PhoneApplicationPage to Null in Destructor. But this throws Invalid Cross Thread Exception. I want to dispose my datacontext when the page is no longer in use. i.e. if user navigates from Page1 to Page2 and then goes back to Page1, I want to dispose Page2 as well [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3616","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3616"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3616\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}