
正文
vb.netexit的简单介绍
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
在.net(C# or vb.net)中,Application.Exit还是Form.Close有什么不同?
Application.Exit()是不管你现在是在启动窗口,还是后来打开的窗口,整个程序都关闭。
Form.Close() 是只关闭此Form窗口,如果此窗口是启动窗口,则程序关闭,如果不是此程序不关闭,只关闭Form.Close()这个语句的Form所代表的窗口。
相关问答
Q1: VB.NET写的智能设备小程序,需要GC么?Application.exit是否能释放资源?
如果一个程序要用Application.exit来退出,那说明太失败了。。。
一般来说,都是用close关闭就可以了。
用.NET平台开发,只要你在操作数据库或者IO的时候没有忘记关闭资源连接,一般是不需要你手动释放的。
Q2: vb.net中如何结束一个线程
vb.net中如何结束一个线程
一般而言,如果您想终止一个线程,您可以使用System.Threading.Thread类的Abort方法. 例如:
Dim worker As ThreadStart = New ThreadStart(AddressOf workerthreadmethod)
Dim t As Thread = New Thread(worker)
t.Start()
MessageBox.Show("Wait for a while for the thread to start.")
MessageBox.Show(t.ThreadState.ToString())
t.Abort()
MessageBox.Show(t.ThreadState.ToString())
t.Join()
MessageBox.Show(t.ThreadState.ToString())
当然,在调用Abort方法后,线程并不是立刻终止,要等线程的所有finally快中的代码完成后才会完全终止. 所以在主线程中可以用Join方法来同步,当线程还未完全终止时,t.Join()将处于等待,直到t线程完全结束后再继续执行后面的语句。
Abort方法是会导致线程跳出一个异常错误的,你需要在代码中捕获该异常。下面是一个比较完整的VB.NET线程例子:
Imports System
Imports System.Threading
Public Class MyTestApp
Public Shared Sub Main()
Dim t As New Thread(New ThreadStart(AddressOf MyThreadMethod))
'Start the thread
t.Start()
MsgBox("Are you ready to kill the thread?")
'Kill the child thread and this will cause the thread raise an exception
t.Abort()
' Wait for the thread to exit
t.Join()
MsgBox("The secondary thread has terminated.")
End Sub
Shared Sub MyThreadMethod()
Dim i As Integer
Try
Do While True
Thread.CurrentThread.Sleep(1000)
Console.WriteLine("This is the secondary thread running.")
Loop
Catch e As ThreadAbortException
MsgBox("This thread is going to be terminated by the Abort method in the Main function")
End Try
End Sub
End Class
Thread.Abort()方法用来永久销毁一个线程,而且将抛出ThreadAbortException异常。使终结的线程可以捕获到异常但是很难控制恢复,仅有的办法是调用Thread.ResetAbort()来取消刚才的调用,而且只有当这个异常是由于被调用线程引起的异常。因此,A线程可以正确的使用Thread.Abort()方法作用于B线程,但是B线程却不能调用Thread.ResetAbort()来取消Thread.Abort()操作。
Q3: vb.net卸载窗体和加载窗体遇到的问题
尽量丢掉vb6的习惯,注意对象的作用域及垃圾回收机制,为对象设定适当的范围,如全局对象下面给个示例(从sub main启动):public module sample public sub main() dim frm as new from1("sample form") frm.show windows.forms.application.run() end subend module public class form1 inherts windows.forms.form private btnnew as new windows.forms.button private btnclose as new windows.forms.button public sub new(byval text as string) me.text=text btnnew.text="new form" btnclose.text="exit" btnnew.location=new drawing.point(30,10) btnclose.location=new drawing.point(30,35) me.controls.add(btnnew) me.controls.add(btnclose) addhandler btnnew.click,addressof btnnew_click addhandler btnclose.click,addressof btnclose_click end sub private sub btnnew_click(byval o as object,byval e as eventargs) me.close() dim newform as new form1("new sample form") newform.show() end sub private sub btnclose_click(byval o as object,byval e as eventargs) windows.forms.application.exit() end subend class
Q4: 窗体的退出事件 vb.net
既然是VB.NETvb.netexit,那么vb.netexit,窗体关闭的事件,是.net framework提供的,是FormClosed事件。也是两个参数,一个object sender这个是object基类,整个.net framework都是从它派生的,一个 EventArgs e,事件处理基类,一切事件是从EventArgs基类派生出来的。
Q5: vb.net如何彻底退出进程?
主窗体代码调用Me.close不就可以了吗?或者在任意代码处调用Application.Exit()。如果不起作用的话是因为你在窗体关闭的事件中调用了e.Handle=True
vb.netexit的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、vb.netexit的信息别忘了在本站进行查找喔。








