Here's another little challenge.
I have a [base] Form from which lots of others will be derived.
One of the base Form properties is a communication "channel"
to an external application. If this external application isn't running,
I want to /prevent/ the creation of the derived Form (essentially
kill the [derived] application stone dead).
I tried throwing an Exception, but being in the Form constructors,
there's nowhere I can easily catch it again, so I get the JIT Debugger
dialog - presumably my users would get something similarly unpleasant.
I even tried (gasp) Application.Exit() but that doesn't seem to work as
I thought it would - given:
[base Form class]
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
Try
ConnectToExternalApp()
Catch ex as MyException
Me.Close()
Me.Dispose()
Application.Exit()
End Try
End Sub
Even with the above, execution resumes in the Sub New() of the
derived Form, although that immediately bombs out with an
ObjectDisposedException - which I can't seem to catch.
Any Suggestions?
TIA,
Phill W. 3 951
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> schrieb Here's another little challenge.
I have a [base] Form from which lots of others will be derived. One of the base Form properties is a communication "channel" to an external application. If this external application isn't running, I want to /prevent/ the creation of the derived Form (essentially kill the [derived] application stone dead).
I tried throwing an Exception, but being in the Form constructors, there's nowhere I can easily catch it again, so I get the JIT Debugger dialog - presumably my users would get something similarly unpleasant. I even tried (gasp) Application.Exit() but that doesn't seem to work as I thought it would - given:
[base Form class]
#Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call Try ConnectToExternalApp() Catch ex as MyException Me.Close() Me.Dispose() Application.Exit() End Try
End Sub
Even with the above, execution resumes in the Sub New() of the derived Form, although that immediately bombs out with an ObjectDisposedException - which I can't seem to catch.
Any Suggestions?
Don't catch the exception in the constructor, so you'll get it where you
create the instance:
dim f as YourForm
try
f = new YourForm
catch
end try
I'd probably do the "ConnectToExternalApp" outside the Form and only create
an instance and pass the necessary data to the Form if ConnectToExternalApp
was successful. This can be put in a Shared Function within the Form class,
and the Function returns a new instance.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de... "Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> schrieb Here's another little challenge.
I have a [base] Form from which lots of others will be derived. One of the base Form properties is a communication "channel" to an external application. If this external application isn't running, I want to /prevent/ the creation of the derived Form (essentially kill the [derived] application stone dead).
.. . .
Don't catch the exception in the constructor, so you'll get it where you create the instance:
Ah! I don't (yet). The inherited form is the "main" (and usually only)
form in the application, and VB is currently starting it for me
- presumably, I'm going to have to change this and insist that my
Developers use Sub Main to get all their programs up and running?
Regards,
Phill W.
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> schrieb I have a [base] Form from which lots of others will be derived. One of the base Form properties is a communication "channel" to an external application. If this external application isn't running, I want to /prevent/ the creation of the derived Form (essentially kill the [derived] application stone dead).
. . .
Don't catch the exception in the constructor, so you'll get it where you create the instance:
Ah! I don't (yet). The inherited form is the "main" (and usually only) form in the application, and VB is currently starting it for me - presumably, I'm going to have to change this and insist that my Developers use Sub Main to get all their programs up and running?
If you want to check something /before/ creating the main Form, yes, you'd
have to write a sub main. That's what I would do, but others will perhaps
make other suggestions. I don't like interrupting creating/showing a Form,
and I also prefer to use a Form only as the user interface and do jobs like
'ConnectToExternalApp' outside the Form, at least if both reasons come
together.
--
Armin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hari Prasad |
last post by:
I wrote an application where I am trying to kill a parent frame with
out killing the child one.
I have created a frame (F1) and if I click a button on F1 I am
getting a new frame (F2). Now, if...
|
by: Colin Steadman |
last post by:
I have created a function to kill all session variables
that aren't in a safe list. This is the function -
Sub PurgeSessionVariables
For Each Item In Session.Contents
Select Case Trim(Item)...
|
by: Philip Herlihy |
last post by:
If I'm reading my reference books correctly, I should be able to pick out
cells in a table by combining a <col> selector with a class selector, like
this:
col#thisid td.thisclass {color: red; }...
|
by: krose |
last post by:
Hi
Using a couple of examples on CodeProject.com I've create a nice little
shell extension (adds some custom menus for proprietary file types).
Everything is working fine, except I can't get it...
|
by: Bagieta |
last post by:
Hi.
Does anyone of you knows any good TDataSet descendant working with DB2?
I want to connect do DB2 directly without ODBC.
Regards
Bagieta
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dbDeveloper...
|
by: Chris |
last post by:
I have a winform base class in which I dynamically set a web reference Url:
myService.Url = <WebServer> + "MyService.asmx";
where <WebServer> is pulled from my App.config file.
There is no...
|
by: Michael Rodriguez |
last post by:
I have a feeling this isn't possible in C#.
In Delphi, when you define event handlers in a base class form, you can
choose them in the properties window on your descendant forms.
As an...
|
by: Haines Brown |
last post by:
Genealogists often display their data as an ascending or descending
chart, and for presentation on the web usually prepare a PDF file or
HTML table. I was interested in a pure CSS solution without...
|
by: Paul Smitton |
last post by:
Hello,
I would like to be able to store some constant data that is specific to each
descendant class.
This data would then be accessable by base class functions. However, I
cannot find out how...
|
by: Roger Heathcote |
last post by:
sjdevnull@yahoo.com wrote:
<snip>
Fair point, but for sub processes that need to be in close contact with
the original app, or very small functions that you'd like 100s or 1000s
of it seems...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |