节目没有结束??? [英] Program not ending???

查看:124
本文介绍了节目没有结束???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行这个程序并退出点击右上角的X.

但显然它并没有真正结束这个程序。如果我返回VB

并进行更改然后尝试重建应用程序,它说exe仍然在

使用 - 我发现它仍然是任务管理器中的一个进程。我需要做什么

才能点击X实际结束程序?

Public Class Form1

继承System.Windows.Forms。表格


#Region" Windows窗体设计器生成的代码


Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

Me.Show()

Application.DoEvents()


Dim result As DialogResult

结果= FolderBrowserDialog1.ShowDialog()

如果result = DialogResult.Cancel那么

结束

结束如果


''创建对当前目录的引用。

Dim DirInfo As New

System.IO.DirectoryInfo(FolderBrowserDialog1.Selec tedPath)

''创建一个表示当前目录中文件的数组。

Dim FileInfo As System.IO.FileInfo()= DirInfo.GetFiles(" *。jpg")


每个文件作为FileInfo中的System.io.FileInfo

Label1.Text = File.FullName

PictureBox1.Image = Image.FromFile(File。 FullName)

Application.DoEvents()

System.Threading.Thread.Sleep(2000)
下一页


结束

结束次级

结束班级

解决方案

" cj" < cj@nospam.nospam> schrieb

我运行此程序并退出单击右上角的X角。但显然它并没有真正结束这个计划。如果我返回VB并进行更改,那么尝试重建应用程序,它说exe仍然在使用 - 我发现它仍然是任务管理器中的一个过程。我需要做些什么来点击X实际上结束程序?

公共类Form1
继承System.Windows.Forms.Form
#Region" Windows窗体设计器生成的代码

Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)Handles MyBase.Load
Me.Show()
Application.DoEvents()


这是糟糕的设计。不要在Form_Load中调用Show。由于Show之前已经执行过,因此已经提高了负载

。我也不知道你为什么要通过调用DoEvents来处理消息队列中的所有Windows消息。

Dim result As DialogResult
result = FolderBrowserDialog1 .ShowDialog()
如果result = DialogResult.Cancel那么
结束


不要使用End。没有必要。

结束如果

''创建对当前目录的引用。
Dim DirInfo As New
System.IO.DirectoryInfo (FolderBrowserDialog1.Selec tedPath)
''创建一个表示当前
目录中文件的数组。暗淡的FileInfo作为System.IO.FileInfo()=
DirInfo.GetFiles(QUOT * JPG"。)

为每个文件作为System.io.FileInfo在FileInfo的
的Label1 .Text = File.FullName
PictureBox1.Image = Image.FromFile(File.FullName)
Application.DoEvents()
System.Threading.Thread.Sleep(2000)
Next

结束
End Sub
End Class



你永远不会退出循环,因此程序永远不会结束。


如果您在Form_Load中执行所有操作,则负载将永远不会完成。

Armin


替代方案建议:


在表格上放置一个Timer(name = Timer1; interval = 2000; enabled = false)。


共享子主( )


Dim f As New Form1

Dim result As DialogResult


f.Show()


result = f.FolderBrowserDialog1.ShowDialog()


如果结果&l吨;> System.Windows.Forms.DialogResult.Cancel然后

f.Start(f.FolderBrowserDialog1.SelectedPath)

Application.Run(F)

结束如果


End Sub


私有f_FileInfos As System.IO.FileInfo()

私有f_Index为整数


公共子开始(ByVal Path As String)


Dim DirInfo As New System.IO.DirectoryInfo(Path)


f_FileInfos = DirInfo.GetFiles(" *。jpg")

如果f_FileInfos.Length> 0然后Timer1.Start()


End Sub

Private Sub Timer1_Tick(_

ByVal sender As System.Object,ByVal e As System.EventArgs)_

处理Timer1.Tick


Dim文件为System.IO.FileInfo


File = f_FileInfos(f_Index)


Label1.Text = File.FullName

PictureBox1.Image = Image.FromFile(File.FullName)


f_Index + = 1


如果f_Index> f_FileInfos.GetUpperBound(0)然后

Timer1.Stop()

结束如果


结束子


Armin





Armin Zingler写道:

" cj" < cj@nospam.nospam> schrieb

我运行此程序并退出单击右上角的X角。但显然它并没有真正结束这个计划。如果我返回VB并进行更改,那么尝试重建应用程序,它说exe仍然在使用 - 我发现它仍然是任务管理器中的一个过程。我需要做些什么来点击X实际上结束程序?

公共类Form1
继承System.Windows.Forms.Form
#Region" Windows窗体设计器生成的代码

Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)Handles MyBase.Load
Me.Show()
Application.DoEvents()
这是糟糕的设计。




或许


Don'' t调用Form_Load中的Show。之前已经执行了Show,因此已经引发了加载。我也不知道你为什么要通过调用DoEvents来处理消息队列中的所有Windows消息。


如果我不打电话给我。显示( )中的程序从来不显示在屏幕
昏暗结果作为DialogResult的
结果= FolderBrowserDialog1.ShowDialog()
如果结果= DialogResult.Cancel然后
结束



不要使用End。没有必要。




如果我没有结束那么如果我选择取消该程序将尝试

工作时目录尚未被选中并且出错。

结束如果

''创建对当前的引用目录。
Dim DirInfo As New
System.IO.DirectoryInfo(FolderBrowserDialog1.Selec tedPath)
''创建一个表示当前
目录中文件的数组。 Dim FileInfo As System.IO.FileInfo()=
DirInfo.GetFiles(" *。jpg")

每个文件作为FileInfo中的System.io.FileInfo
Label1 .Text = File.FullName
PictureBox1.Image = Image.FromFile(File.FullName)
Application.DoEvents()
System.Threading.Thread.Sleep(2000)
Next

结束
结束类



你永远不会退出循环,因此程序永远不会结束。




这是每个循环。显示所有文件时循环退出。

如果您在Form_Load中执行所有操作,则负载将永远不会完成。


胡?当其中的所有内容完成时,负载将完成。

最后做的就是结束程序。

Armin




为什么不会点击X只是突然结束程序而不是

只是删除表单并留下一些东西?


I run this program and to exit click the X in the upper right corner.
But apparently it isn''t really ending the program. If I return to VB
and make changes then try to rebuild the app it says the exe is still in
use--I find it is still a process in Task Manager. What do I need to do
to make clicking that X actually end the program?
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Show()
Application.DoEvents()

Dim result As DialogResult
result = FolderBrowserDialog1.ShowDialog()
If result = DialogResult.Cancel Then
End
End If

'' Create a reference to the current directory.
Dim DirInfo As New
System.IO.DirectoryInfo(FolderBrowserDialog1.Selec tedPath)
'' Create an array representing the files in the current directory.
Dim FileInfo As System.IO.FileInfo() = DirInfo.GetFiles("*.jpg")

For Each File As System.io.FileInfo In FileInfo
Label1.Text = File.FullName
PictureBox1.Image = Image.FromFile(File.FullName)
Application.DoEvents()
System.Threading.Thread.Sleep(2000)
Next

End
End Sub
End Class

解决方案

"cj" <cj@nospam.nospam> schrieb

I run this program and to exit click the X in the upper right
corner. But apparently it isn''t really ending the program. If I
return to VB and make changes then try to rebuild the app it says
the exe is still in use--I find it is still a process in Task
Manager. What do I need to do to make clicking that X actually end
the program?
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Show()
Application.DoEvents()
This is bad design. Don''t call Show in Form_Load. Load has been raised
because Show has been executed before. I also don''t know why you want to
process all windows messages in the message queue by calling DoEvents.
Dim result As DialogResult
result = FolderBrowserDialog1.ShowDialog()
If result = DialogResult.Cancel Then
End
Don''t use End. It is not necessary.
End If

'' Create a reference to the current directory.
Dim DirInfo As New
System.IO.DirectoryInfo(FolderBrowserDialog1.Selec tedPath)
'' Create an array representing the files in the current
directory. Dim FileInfo As System.IO.FileInfo() =
DirInfo.GetFiles("*.jpg")

For Each File As System.io.FileInfo In FileInfo
Label1.Text = File.FullName
PictureBox1.Image = Image.FromFile(File.FullName)
Application.DoEvents()
System.Threading.Thread.Sleep(2000)
Next

End
End Sub
End Class


You never exit the loop, thus the program never ends.

If you do everything in Form_Load, the load will never be complete.
Armin


Alternative suggestion:

Put a Timer (name=Timer1; interval=2000; enabled=false) on the Form.

Shared Sub main()

Dim f As New Form1
Dim result As DialogResult

f.Show()

result = f.FolderBrowserDialog1.ShowDialog()

If result <> System.Windows.Forms.DialogResult.Cancel Then
f.Start(f.FolderBrowserDialog1.SelectedPath)
Application.Run(f)
End If

End Sub

Private f_FileInfos As System.IO.FileInfo()
Private f_Index As Integer

Public Sub Start(ByVal Path As String)

Dim DirInfo As New System.IO.DirectoryInfo(Path)

f_FileInfos = DirInfo.GetFiles("*.jpg")
If f_FileInfos.Length > 0 Then Timer1.Start()

End Sub
Private Sub Timer1_Tick( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Timer1.Tick

Dim File As System.IO.FileInfo

File = f_FileInfos(f_Index)

Label1.Text = File.FullName
PictureBox1.Image = Image.FromFile(File.FullName)

f_Index += 1

If f_Index > f_FileInfos.GetUpperBound(0) Then
Timer1.Stop()
End If

End Sub

Armin




Armin Zingler wrote:

"cj" <cj@nospam.nospam> schrieb

I run this program and to exit click the X in the upper right
corner. But apparently it isn''t really ending the program. If I
return to VB and make changes then try to rebuild the app it says
the exe is still in use--I find it is still a process in Task
Manager. What do I need to do to make clicking that X actually end
the program?
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Show()
Application.DoEvents()
This is bad design.



Perhaps

Don''t call Show in Form_Load. Load has been raised because Show has been executed before. I also don''t know why you want to
process all windows messages in the message queue by calling DoEvents.

If I don''t call me.show() the program never displays on the screen

Dim result As DialogResult
result = FolderBrowserDialog1.ShowDialog()
If result = DialogResult.Cancel Then
End



Don''t use End. It is not necessary.



If I don''t put end there then if I choose cancel the program will try to
work when a directory has not been selected and it gives an error.

End If

'' Create a reference to the current directory.
Dim DirInfo As New
System.IO.DirectoryInfo(FolderBrowserDialog1.Selec tedPath)
'' Create an array representing the files in the current
directory. Dim FileInfo As System.IO.FileInfo() =
DirInfo.GetFiles("*.jpg")

For Each File As System.io.FileInfo In FileInfo
Label1.Text = File.FullName
PictureBox1.Image = Image.FromFile(File.FullName)
Application.DoEvents()
System.Threading.Thread.Sleep(2000)
Next

End
End Sub
End Class


You never exit the loop, thus the program never ends.



It''s a for each loop. The loop exits when all the files are displayed.

If you do everything in Form_Load, the load will never be complete.
Hu? the load would be complete when everything in it is done. And the
last thing that is done is ending the program.


Armin



Why wouldn''t clicking the X just abruptly end the program instead of
just removing the form and leaving something running?


这篇关于节目没有结束???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆