469,579 Members | 1,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Application.Exit() did not exist the application.

Hi,
I used System.Windows.Forms.Application.DoEvents() in a loop to handle user
click close button .

Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
Me.Close()
System.Windows.Forms.Application.Exit
End Sub

However, the application continues to run when user click close, thought the
form did close.

Is there anything I miss out?

Thanks.
Nov 20 '05 #1
22 2055
ah, good ol logic error.
Me.Close() did what it was supposed to. Closed the form and stopped execution
of the form along with it's resources.
The Application.Exit command never got processed.
You could just remove the Me.Close().
If you want to make the form go away but continue to run, you might try
Me.Hide().
Then the Application.Exit command should execute.
Although if your code was still running, this might not be the most graceful way
or appropriate place to exit.

Gerald

"Shelby" <sh****@itsupport.com.sg> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl...
Hi,
I used System.Windows.Forms.Application.DoEvents() in a loop to handle user
click close button .

Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
Me.Close()
System.Windows.Forms.Application.Exit
End Sub

However, the application continues to run when user click close, thought the
form did close.

Is there anything I miss out?

Thanks.

Nov 20 '05 #2
Hi,
I have change to
Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
System.Windows.Forms.Application.Exit
End Sub

The application is still running and the form also close without the
me.close() statement.

"Cablewizard" <Ca*********@Yahoo.com> wrote in message
news:Os****************@TK2MSFTNGP12.phx.gbl...
ah, good ol logic error.
Me.Close() did what it was supposed to. Closed the form and stopped execution of the form along with it's resources.
The Application.Exit command never got processed.
You could just remove the Me.Close().
If you want to make the form go away but continue to run, you might try
Me.Hide().
Then the Application.Exit command should execute.
Although if your code was still running, this might not be the most graceful way or appropriate place to exit.

Gerald

"Shelby" <sh****@itsupport.com.sg> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl...
Hi,
I used System.Windows.Forms.Application.DoEvents() in a loop to handle user click close button .

Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
Me.Close()
System.Windows.Forms.Application.Exit
End Sub

However, the application continues to run when user click close, thought the form did close.

Is there anything I miss out?

Thanks.


Nov 20 '05 #3
Just put a simple End in the Sub
Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
End
End Sub
This Should do it.

Manny
"Shelby" <sh****@itsupport.com.sg> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl... Hi,
I used System.Windows.Forms.Application.DoEvents() in a loop to handle user click close button .

Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
Me.Close()
System.Windows.Forms.Application.Exit
End Sub

However, the application continues to run when user click close, thought the form did close.

Is there anything I miss out?

Thanks.

Nov 20 '05 #4
Thank you...

"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:YzsEc.38940$_5.11257@clgrps13...
Just put a simple End in the Sub
Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click


End
End Sub


This Should do it.

Manny
"Shelby" <sh****@itsupport.com.sg> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl...
Hi,
I used System.Windows.Forms.Application.DoEvents() in a loop to handle

user
click close button .

Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
Me.Close()
System.Windows.Forms.Application.Exit
End Sub

However, the application continues to run when user click close, thought

the
form did close.

Is there anything I miss out?

Thanks.


Nov 20 '05 #5
Hi Shelby,

Using that *end* statement is worse than setting the power of from your
computer.

When the me.close is on the main form, that is normaly enough, you do not
need that application.exit

However when it is not on the mainclass, you have normally to close in the
class where you started the application.

I hope this helps?

Cor
Nov 20 '05 #6

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O0**************@tk2msftngp13.phx.gbl...
Hi Shelby,

Using that *end* statement is worse than setting the power of from your
computer.


I am interesting in knowing why you think this?

Best Regards,
Andy
Nov 20 '05 #7
* "Andy Becker" <x@x.com> scripsit:
Using that *end* statement is worse than setting the power of from your
computer.


I am interesting in knowing why you think this?


<msdn>
The End statement can be placed anywhere in a procedure to end code
execution, close files opened with an Open statement, and clear
variables. The End statement calls the Exit method of the Environment
class in the System namespace. System.Environment.Exit requires that you
have SecurityPermissionFlag.UnmanagedCode permissions. If you do not, a
SecurityException error occurs.

When executed, the End statement clears all variables at module and
class level and all static local variables in all modules.

Note The End statement stops code execution abruptly, without invoking
the Finalize method or any other Visual Basic code. Object references
held by other programs are invalidated.

The End statement provides a way to force your program to halt. Your
program closes as soon as there are no other programs holding references
to its objects and none of its code is executing.

If your application has any forms open, you should close them before
executing End. A console application can either use End or simply return
from the Main procedure.
</msdn>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
> > Hi Shelby,

Using that *end* statement is worse than setting the power of from your
computer.


I am interesting in knowing why you think this?


Because it stops direct the program and does not free any resources anymore.
(It kills the process). When you power off than the resources are directly
freeed when you put the power on again.
Cor
Nov 20 '05 #9

"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:YzsEc.38940$_5.11257@clgrps13...
Just put a simple End in the Sub
Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click


End


Oh man, that thing still exists in .NET?

And what's even worse is that people STILL suggest it!!
Nov 20 '05 #10
> The application is still running and the form also close without the
me.close() statement.

The above statement leads me to believe that there are other things going on we
need to account for.
It sounds as if we need a little more information about the structure of your
program.
Is this a Form based app? Single or multi-threaded? Do you know?
What created the form? Is it your default form that starts up, or did you spawn
it from someplace else, such as as module or class?
I used System.Windows.Forms.Application.DoEvents() in a loop to handle user
click close button .

Now this is interesting. Can you give us a sample of what you are doing and why?
Am I really to read this as something like:

Do
System.Windows.Forms.Application.DoEvents()
Loop

I can't imagine a scenario where that alone would be a good thing.
Give us a little more info so we can point you in the right direction.

Gerald
Nov 20 '05 #11
Ouch. Somewhere in the back of my mind, I was hoping that VB.NET would have
done something more graceful.

And I'm sure that somewhere, in the back of everyone else's mind who is
reading this, they were hoping I would RTFM before posting trash. :-)

Best Regards,
Andy
Nov 20 '05 #12
Well people I suggested it because freaking MICROSOFT is putting that *end*
statement on their sample applications!!!
sorry about that.

Manny.

"Shelby" <sh****@itsupport.com.sg> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl...
Hi,
I used System.Windows.Forms.Application.DoEvents() in a loop to handle user click close button .

Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
Me.Close()
System.Windows.Forms.Application.Exit
End Sub

However, the application continues to run when user click close, thought the form did close.

Is there anything I miss out?

Thanks.

Nov 20 '05 #13
Hi Manuel,
Well people I suggested it because freaking MICROSOFT is putting that *end* statement on their sample applications!!!
sorry about that.


I thought that I has seen that also once. I thought it was a sample with
more errors (some C code in it as wel)l, can it be the same?

And do not look at the message from non a regulars in this newsgroup, who
send messages in a kind of flaming way. They regulars of this newsgroup are
helping you when that goes to far you know.

So go on in the way you was starting with.

:-)

Cor
Nov 20 '05 #14
Hi Cor,

this project is a COM Addin for Outlook.
Currently for the testing purposes, I have set it as a Console Application,
and set the StartUp to a particular Form.

In both case, are they in the mainclass?
What do you mean by have to close in the class where I start the
application?

Shelby
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O0**************@tk2msftngp13.phx.gbl...
Hi Shelby,

Using that *end* statement is worse than setting the power of from your
computer.

When the me.close is on the main form, that is normaly enough, you do not
need that application.exit

However when it is not on the mainclass, you have normally to close in the
class where you started the application.

I hope this helps?

Cor

Nov 20 '05 #15
Hi Shelby,

Probably the same as what you call your main class

Cor
this project is a COM Addin for Outlook.
Currently for the testing purposes, I have set it as a Console Application, and set the StartUp to a particular Form.

In both case, are they in the mainclass?
What do you mean by have to close in the class where I start the
application?

Nov 20 '05 #16
"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...


Oh man, that thing still exists in .NET?

And what's even worse is that people STILL suggest it!!


I'm just now learning NET and about every tutorial I've read (including ones
from MS) say this is how to end the program. Is it OK to use it? Right now
I'm doing programs with a single form so is it OK then?
Nov 20 '05 #17
Hi,
I'm still having this problem.
The actual scenario is this:

when I click on a Button, it will call a function.
This function will connect to database and retrieve thousands of records.

So if I click the "Cancel" button halfway, how should I terminate the
program? If I just use Me.Close(), the form will only close, but the
function is still running. Because before I close the form, I will close the
connection. And therefore the function raise an error that there's no
connection.

Thanks
Shelby

Nov 20 '05 #18
Hi Shelby,

Do you use the clossing event of the form where you button is on to close
everything that is running?

And then How?

Cor
Nov 20 '05 #19
* "Shelby" <sh****@itsupport.com.sg> scripsit:
when I click on a Button, it will call a function.
This function will connect to database and retrieve thousands of records.

So if I click the "Cancel" button halfway, how should I terminate the
program? If I just use Me.Close(), the form will only close, but the
function is still running. Because before I close the form, I will close the
connection. And therefore the function raise an error that there's no
connection.


You could set a private Boolean variable that is checked by the
procedure every n iterations. If it's set, the function returns and the
operation is cancelled, so the form can be closed.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #20

"Ricky W. Hunt" <rh*****@hotmail.com> wrote in message
news:F31Gc.8510$JR4.8419@attbi_s54...
I'm just now learning NET and about every tutorial I've read (including ones from MS) say this is how to end the program. Is it OK to use it?
NO!!
Right now I'm doing programs with a single form so is it OK then?


NEVER!!

Close the form with Me.Close() (preferred) or use Application.Exit().
Nov 20 '05 #21
Hi Cor,

this is my code:
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btncancel.Click
If cn.State = 1 Then
cn.Close()
End If
Me.Close()
End Sub

And hopefully that's the end... But it's not however.
Is it possible to terminate all function calls also?

Shelby
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eJ**************@TK2MSFTNGP11.phx.gbl...
Hi Shelby,

Do you use the clossing event of the form where you button is on to close
everything that is running?

And then How?

Cor

Nov 20 '05 #22
Hi Shelby,

I do not know however for sure not when I do not know how you did call those
functions, if it is intererop and if there and/are multithreads used?

By instance what is cn?

Cor

this is my code:
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btncancel.Click
If cn.State = 1 Then
cn.Close()
End If
Me.Close()
End Sub

Nov 20 '05 #23

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ramprasad A Padmanabhan | last post: by
4 posts views Thread by Rajesh Abraham | last post: by
3 posts views Thread by Mike Johnson | last post: by
13 posts views Thread by Matthew | last post: by
2 posts views Thread by neilphan | last post: by
11 posts views Thread by Rahul | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.