Application.Exit() did not exist the application.

  • Thread starter Thread starter Shelby
  • Start date Start date
S

Shelby

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.
 
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
 
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.
 
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
 
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
 
Cor Ligthert said:
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
 
* "Andy Becker said:
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>
 
Hi Shelby,
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
 
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
 
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
 
Well people I suggested it because freaking MICROSOFT is putting that *end*
statement on their sample applications!!!
sorry about that.

Manny.
 
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
 
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
 
Jeff Johnson said:
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?
 
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
 
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
 
* "Shelby said:
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.
 
Back
Top