在VB.NET中使用模块/全局变量的问题 [英] Problem using module/global variables in VB.NET
本文介绍了在VB.NET中使用模块/全局变量的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在模块中定义文件流并使其成为全局文件,但没有其他模块/ aspx.vb文件可以看到它。
代码在'你有什么尝试'是我的Default.aspx.vb
感谢您的帮助,我真的,真的卡住了。
我尝试了什么:
I'm trying to define a Filestream in a module and make it global, but no other modules/aspx.vb files can see it.
The code in 'What have you tried' is my Default.aspx.vb
Thanks for any help, I'm really, really stuck.
What I have tried:
Class _Default
Inherits System.Web.UI.Page
Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
Public Module GlobalVars
Public wFile As System.IO.FileStream
Sub main()
wFile = New System.IO.FileStream("C:\test.txt", System.IO.FileMode.Append)
End Sub
End Module
推荐答案
ASP.NET应用程序没有Main
方法作为其入口点。您的Sub main()
代码永远不会被执行。
最接近的等价物是Application_Start
中的事件Global.asax
:
IIS 5.0和6.0的ASP.NET应用程序生命周期概述 [ ^ ]
然而,ASP。 NET是一个多用户,多线程系统。在全局/共享变量中存储数据几乎总是错误的。
ASP.NET applications do not have aMain
method as their entry-point. YourSub main()
code will never be executed.
The closest equivalent would be theApplication_Start
event inGlobal.asax
:
ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0[^]
However, ASP.NET is a multi-user, multi-threaded system. Storing data in global / shared variables is almost always the wrong thing to do.
这篇关于在VB.NET中使用模块/全局变量的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文