Exiting an Application from a class Library

  • Thread starter Thread starter Juan Pedro Gonzalez
  • Start date Start date
J

Juan Pedro Gonzalez

Helo,

My question is how can I exit an application from a class Library...

I've got a class library wich I use to load and save user setting for my
application, some of this settings are mandatory, therefore if the setting
is not present the application should exit. I know I could throw an
exception to the main program, or even return nothing, make a check wich
will close the application if its Nothing. But this means more code on the
program side, and I would like to relief the program code from this checks
passing them to the class library (after all the class was made in order to
realieve coding and coding errors in case you forgot a check).

I've tried passing the "application" 'class' to the class inside my class
library, but .NET will say it's a type and it can't be passed as a
parameter, therefore "application.exit" seems to be unaccesible from my
class library.

What could I do to close the application from the class library?

Thanks in advance,

Juan
 
Nice Posting Juan,

here is the code:

Public Class LoadSettings
Delegate Sub ApplicationExit()

Public Shared Sub LoadSettings(ByRef CallThisFunction As
ApplicationExit)
CallThisFunction.Invoke()
End Sub

End Class

Call it this way

LoadSettings.LoadSettings(New LoadSettings.ApplicationExit(AddressOf
Application.Exit))

Hope it works. :)
Helo,

My question is how can I exit an application from a class Library...

I've got a class library wich I use to load and save user setting for my
application, some of this settings are mandatory, therefore if the setting
is not present the application should exit. I know I could throw an
exception to the main program, or even return nothing, make a check wich
will close the application if its Nothing. But this means more code on the
program side, and I would like to relief the program code from this checks
passing them to the class library (after all the class was made in order to
realieve coding and coding errors in case you forgot a check).

I've tried passing the "application" 'class' to the class inside my class
library, but .NET will say it's a type and it can't be passed as a
parameter, therefore "application.exit" seems to be unaccesible from my
class library.

What could I do to close the application from the class library?

Thanks in advance,

Juan

--

Best,
_____________
Bharat Sharma

* TEN Technologies.
* Official Web: _www.ten-technologies.com_
<http://www.ten-technologies.comemail/>
Personal Web: _www.bharatsharma.net_ <http://www.bharatsharma.net/>
 
Thank you Bharat, It work perfectlly! :)

"Bharat Sharma" <[email protected]> escribió en el mensaje Nice Posting Juan,

here is the code:

Public Class LoadSettings
Delegate Sub ApplicationExit()

Public Shared Sub LoadSettings(ByRef CallThisFunction As ApplicationExit)
CallThisFunction.Invoke()
End Sub

End Class

Call it this way

LoadSettings.LoadSettings(New LoadSettings.ApplicationExit(AddressOf Application.Exit))

Hope it works. :)


--

Best,
_____________
Bharat Sharma

TEN Technologies.
Official Web: www.ten-technologies.com
Personal Web: www.bharatsharma.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top