{"id":20043,"date":"2008-11-28T10:00:00","date_gmt":"2008-11-28T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/11\/28\/just-because-a-method-is-called-refresh-doesnt-mean-that-it-refreshes-what-you-want\/"},"modified":"2008-11-28T10:00:00","modified_gmt":"2008-11-28T10:00:00","slug":"just-because-a-method-is-called-refresh-doesnt-mean-that-it-refreshes-what-you-want","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20081128-00\/?p=20043","title":{"rendered":"Just because a method is called Refresh doesn&#8217;t mean that it refreshes what you want"},"content":{"rendered":"<p>Here&#8217;s a question from a customer:<\/p>\n<blockquote class=\"q\"><p> I made some changes related to my shell extension [details omitted], but the changes don&#8217;t show up in the Explorer window when I refresh it. Any suggestions on how to solve this problem? <\/p><\/blockquote>\n<p> When we asked how they were refreshing the Explorer window, we were expecting something like pressing F5 or calling <code>SHChangeNotify<\/code> with <code>SHCNE_UPDATEDIR<\/code>, or maybe calling <code>IShellView::Refresh<\/code> or possibly even calling <code>WebBrowser.Refresh<\/code> from script. But we definitely didn&#8217;t expect this response: <\/p>\n<blockquote class=\"q\"><p> I&#8217;m invoking the <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/system.diagnostics.process.refresh.aspx\"> Process.Refresh() method from the <\/a><a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/15t15zda.aspx\"> <code>System.Diagnostics<\/code><\/a> namespace. <\/p><\/blockquote>\n<p> Just because a method is called <code>Refresh<\/code> doesn&#8217;t mean that it refreshes what you want. I think this is somebody who just saw a method name, perhaps <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/09\/02\/8918130.aspx#8920037\"> inspired by IntelliSense<\/a> and&mdash; <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/09\/02\/8918130.aspx#8920189\"> Boom! You have it!<\/a>&mdash;assumed it did what was needed without actually reading the documentation to check. But you don&#8217;t even need to read the documentation to know that <code>Process.Refresh<\/code> has no chance of working. <\/p>\n<p> Since it&#8217;s a method on the <code>Process<\/code> class, the method is applicable to all processes. But certainly there is no generic way to tell a process to refresh. This magical <code>Refresh<\/code> method would have to know how to refresh Explorer windows, Firefox web pages, iTunes mp3 tags&#8230; And what would it even mean to refresh, say, a Notepad window? Does that mean to throw away all changes and reload the original document? <\/p>\n<p> How do you know that there is no generic way to tell a process to refresh? Well, for one thing, a single process like Explorer can be viewing multiple objects that can be refreshed; which one are you refreshing? Second, when you write your own program, how do <i>you<\/i> implement refresh? Do you respond to some standard system Refresh message? Or do you just add a Refresh option to your program&#8217;s main menu and give it some arbitrary command ID? If there&#8217;s not even a standard way to refresh <i>your<\/i> program&#8217;s window, then how can there be a standard way to refresh <i>all<\/i> program windows? <\/p>\n<p> In this specific case, the <code>Process.Refresh<\/code> method refreshes the <code>Process<\/code> object&#8217;s internal cache of process properties. It doesn&#8217;t actually do anything to the process itself. How could it? <\/p>\n<p> It&#8217;s like <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/09\/02\/8918130.aspx#8920421\"> thinking that the <code>Matrix.Rotate<\/code> method rotates the entries in a matrix<\/a>. <\/p>\n<p> <b>Epilogue<\/b> <\/p>\n<p> Actually, I&#8217;m scared by this customer&#8217;s question for another reason: The fact that they even mentioned <code>Process.Refresh<\/code> suggests to me that they wrote their shell extension in managed code, which we already know <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/12\/18\/1317290.aspx\"> is strongly disrecommended<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a question from a customer: I made some changes related to my shell extension [details omitted], but the changes don&#8217;t show up in the Explorer window when I refresh it. Any suggestions on how to solve this problem? When we asked how they were refreshing the Explorer window, we were expecting something like pressing [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-20043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Here&#8217;s a question from a customer: I made some changes related to my shell extension [details omitted], but the changes don&#8217;t show up in the Explorer window when I refresh it. Any suggestions on how to solve this problem? When we asked how they were refreshing the Explorer window, we were expecting something like pressing [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/20043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=20043"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/20043\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=20043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=20043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=20043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}