By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,032 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,032 IT Pros & Developers. It's quick & easy.

close application after a security exception

P: n/a
Hi all,

I've a window form application with 3 forms. I want to catch the
security exception when users run this application from a network share,
thus I've made this code (I've notice that excpetion has been throw by
initializecomponent()):

Try
InitializeComponent()
Catch ex As Security.SecurityException
MessageBox.Show(....)
me.close()
End Try

I've made this in the main form, but all forms throw the exception
causing debugger window appear to users, thus, I've made the try-catch
block on all 2 other forms InitializeComponent.

The messagebox appears 3 times (one per form) but the application wan't
close: a debugger window appear...

How can I do to application close after a messagebox to inform users?

thanks in advance and sorry for my bad english
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Nicola,

Me close means that the current instanced class closes.

Therefore probably as I understand you well, is the me.close not done in
your main class.

It is important what kind of form it is where you talking about when you
want some help to do it.
Mdi child,
a form showed with showdialog
a form showed with show.

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
Cor Ligthert ha scritto:
It is important what kind of form it is where you talking about when you
want some help to do it.


Simply it's the main form of the application (start form); when i launch
the application, the main form "initializecomponent()" method throw
that exception.... i want to catch her, show a message and close the
application.

I hope it's more clear...

thanks

P.S. also all other 2 forms in the application throw that exception, on
application launch...
Nov 21 '05 #3

P: n/a
Nicola,

When you write two other forms, than there has to be a difference. There are
not 3 main forms.

When you set in your main form me.close and you don't cancel that in your
closing event, than the application stops.

This assuming that you have not created yourself a kind of module to start
that mainform (than there is in my opinion actually not a mainform)

Cor
Nov 21 '05 #4

P: n/a
Cor Ligthert ha scritto:
This assuming that you have not created yourself a kind of module to start
that mainform (than there is in my opinion actually not a mainform)


Thanks Cor for your patience,

the main form is set in visual studio, not from a custom module: is this
the problem?

For a better explanation of my application:

1 Main form (application start here)
1 Options form (open in showdialog from a menu)
1 About form (open in showdialog from a menu))

Main form is the first form that i created in visual studio, and so is
set as first form to show when application start; have I to create a
module to start this form? Then can I close it with me.close()?

When I run the application from a network share, "initializecomponent()"
of all 3 forms throw the security exception... I don't know why all 3!

thanks
Nov 21 '05 #5

P: n/a
Nicola,

I show you a simple approach that should be work. (From what you show it
should throw three times an error however stop directly in the first form,
when you not have used a module (with sub main) or something else to stop
your application. Therefore I still don't unerstand it.
1 Main form (application start here)


dim Optfrm as new OptionForm
Optfrm.showdialog
if Optfrm.CloseAp then
Optfrm.dispose
me.close
end if
dim AboutFrm as new Aboutform
if AboutFrm.CloseAp then
OptFrm.dispose
me.close
end if
.....

And in those 2 forms
A global Boolean
Friend CloseAp as Boolean
And before your close
CloseAp = True
before me.close

Why the security issue now throws 3 times this error I don't know. that is
really not visible for me. However, in your case I would ask for that not
working security in the dotnet newsgroup for that, I never answer those
questions.

I hope this helps,

Cor
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.