开发者

How to Create Global.asax in Winform Application? - C#/.NET

I'm trying to create Global.asax in a Winform. I could do it in ASP.NET, but i couldn't find a way for Windows Application. Any help will be appreciated.

I have开发者_如何学编程 a singleton class called DataAccessLayer, i need to instantiate it once only, so i can call its method/properties anywhere in the application easily.


You cannot add a Global.asax to a winform application in the same way that you cannot add an aspx page it. They are parts of webforms.

The purpose of Global.asax is to define application and session events and objects. You can do this from the Main() method of you winform application.


That's because a Global.asax is designed only for an Asp.NET application. What are you trying to accomplish? We may have an alternative solution for you.

Just guessing, but one of the more popular uses of a global.asax is for application-wide exception handling. If that's your aim, you should see this previous post. Otherwise, please ask a new question with details on what you are trying to accomplish.


If you just need a global access point, put in a Global.cs normal class, and put your static references in there.


My DataAccessLayer class is set as Singleton (sealed)


Sounds like you want to load global variables and then perform and unload when the program ends.
Use a static class like Oded mentioned.
You can also look into the Application.ApplicationExit Event for an equivalend to Application_End and Session_End http://msdn.microsoft.com/en-us/library/system.windows.forms.application.applicationexit.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜