[Silverlight入門系列]Prism如何卸載模組(Unload Module)

來源:互聯網
上載者:User

用Prism的童鞋們都知道Module可以動態載入,那麼如何動態卸載模組(Unload module)呢?這個需求也不變態,通常有使用者登入功能,登入的時候動態載入該使用者可以訪問的模組,那麼登出的時候呢就需要動態卸載這些模組,然後用另外一個使用者登入。模組卸載這個事兒據我所知,是不可能的,這兒和這兒有討論,具體原因是這樣的:

No, it's not possible. This is a CLR restriction, not a PRISM or even a Silverlight restriction. You can only unload an entire AppDomain, not individual assemblies within the domain. If the user is logging out you could post back to the site in an unauthorized state and the whole plugin will unwind. If you're looking to manage memory during runtime, your best solution is to de-reference any objects as soon as possible to allow garbage collection to deal with them.

登出卸載Prism模組的替代實現方法

我能想到的替代方法是當使用者點擊登出成功退出以後重新整理一下瀏覽器(重新整理首頁)就行了。具體做法就是:

1. 在web項目的home.aspx的body裡寫一個重新整理的js:

<script type="text/javascript">

function RefreshSL() { window.location.reload(); }

</script>

2. 在Silverlight中引用System.Window.Brwoser,然後調用哪個js即可:

HtmlPage.Window.Invoke("RefreshSL","Invoke");

就這麼簡單。有更好的辦法請通知我。

有關Assembly.Unload的參考資料
  • Why isn't there an Assembly.Unload method?
  • 有關Assembly.Unload
  • 完整的動態載入/卸載程式集的解決方案
  • 通過應用程式定義域AppDomain載入和卸載程式集
  • 動態load assembly 動態unload assembly

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.