[譯]Visual Basic 2005在語言上的增強(十)應用程序級別事件

另一個令你垂涎的新特性是這套嶄新出爐的應用程序級別事件,你在一系列名爲MyApplication的部分類中可以找到它。你可以在解決方案資源管理器中查找My Project項目中的一個名爲MyEvents.vb的文件。你也同樣可以點擊Application面板上的View Code按鍵,然後在代碼編輯器中查看它。

這些新的應用程序級別事件類似於ASP.NET應用程序中global.asax文件裏的應用程序事件。共暴露了五個事件:
·  Shutdown
·  Startup
·  StartupNextInstance
·  NetworkAvailabilityChanged
·  UnhandledException


當應用程序啓動或關閉時,前三個事件被引發。當機器網絡狀態發生變化時,NetworkAvailabilityChanged事件被引發。爲了防止系統拋出一個你在其他地方未曾處理的異常,你還可以在UnhandledException事件下添加代碼。

@以下是原文供大家參考@

Application Level Events

Another new feature you'll want to take advantage of is a new set of Application-level events available in a partial class named MyApplication. Look for a file named MyEvents.vb under the My Project item in Solution Explorer. You can also find this file behind the View Code button on the Application tab in the application designer.

These new Application-level events are similar to the application events in the global.asax file in an ASP.NET application. Five events are exposed:
• Shutdown
• Startup
• StartupNextInstance
• NetworkAvailabilityChanged
• UnhandledException


The first three events are fired as the application starts up and shuts down. NetworkAvailabilityChanged fires when the network state changes on the machine. Put code in the UnhandledException event in case an exception is thrown that you don't handle anywhere else.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章