473,416 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How to determine if calling app is window or console

I have a exception handling class that could be called from either a windows
project app or a console project app. Is there any way for this class to
determine which type of app called it without sending an window/console
parameter from either app?

Thanks,
Dean Slindee
Nov 20 '05 #1
3 1946
I can't help you with that determination (it may not be easy, if it's even
possible), and the following comments may be way off base. I apologize if
this is so. But I suspect that the reason you're trying to find this out is
so that you can decide whether to display dialogs in the class. If this is
where you're going, I'd like to suggest that you leave the decision about UI
interactions to the code that is using your class, rather than doing it
within your class. Over the years, every time I've written library classes
that displayed dialogs, on the assumption that they were going to be used
exclusively in interactive applications and that the interactive
applications would always want the dialogs to be displayed, I've almost
always later regretted it, and have had to retrofit them with kludges such
as boolean arguments that determine whether or not to display dialogs. So in
general I'd recommend leaving the UI interaction out of the libraries, and
let the application decide what to do with the results of processing.

Tom Dacon
Dacon Software Consulting

"Dean Slindee" <sl*****@charter.net> wrote in message
news:10*************@corp.supernews.com...
I have a exception handling class that could be called from either a windows project app or a console project app. Is there any way for this class to
determine which type of app called it without sending an window/console
parameter from either app?

Thanks,
Dean Slindee

Nov 20 '05 #2
Tom,
You're right on the mark with your assumption. I want to display one (and
only one) exception dialog to the user, tellling him what went wrong, and
providing a textbox where the user can enter any helpful comments about what
he was doing just before the exception occurred. In addition, the exception
class would send the exception (and comments) via email to the help desk,
append an image of the foreground window or desktop to the email, while
logging everything to the application's exception table.

I am writing the application(s) where the exception class would be used, not
marketing the code as an "addin". Could you provide a few examples from
your experience where this approach of putting the dialog box in the
exception class became a burden? Perhaps I can better judge....

Thanks for your reply.
Dean Slindee
"Tom Dacon" <td****@community.nospam> wrote in message
news:OA**************@TK2MSFTNGP11.phx.gbl...
I can't help you with that determination (it may not be easy, if it's even
possible), and the following comments may be way off base. I apologize if
this is so. But I suspect that the reason you're trying to find this out is so that you can decide whether to display dialogs in the class. If this is
where you're going, I'd like to suggest that you leave the decision about UI interactions to the code that is using your class, rather than doing it
within your class. Over the years, every time I've written library classes
that displayed dialogs, on the assumption that they were going to be used
exclusively in interactive applications and that the interactive
applications would always want the dialogs to be displayed, I've almost
always later regretted it, and have had to retrofit them with kludges such
as boolean arguments that determine whether or not to display dialogs. So in general I'd recommend leaving the UI interaction out of the libraries, and
let the application decide what to do with the results of processing.

Tom Dacon
Dacon Software Consulting

"Dean Slindee" <sl*****@charter.net> wrote in message
news:10*************@corp.supernews.com...
I have a exception handling class that could be called from either a

windows
project app or a console project app. Is there any way for this class to determine which type of app called it without sending an window/console
parameter from either app?

Thanks,
Dean Slindee


Nov 20 '05 #3
Dean,
In addition to Tom's comments.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.

In your example: for my Windows Console application I would only handle the
AppDomain.UnhandledException event, possible using the Console API to query
the user, and send the results. For a Windows Forms application I would
handle at least the Application.ThreadException and possible the
AppDomain.UnhandledException (based on the info in the above link) using a
Windows Form to query the user and send the results. For a Windows Service I
would not query the user, instead simply logging & sending the info...

Because the event handlers are local to the application they would know what
type of application it is...

In either case I would log the information also, in case physically sending
is not an option.

Hope this helps
Jay
"Dean Slindee" <sl*****@charter.net> wrote in message
news:10*************@corp.supernews.com...
I have a exception handling class that could be called from either a windows project app or a console project app. Is there any way for this class to
determine which type of app called it without sending an window/console
parameter from either app?

Thanks,
Dean Slindee

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Randell D. | last post by:
Folks, I have got this working before, in part with some help from this ng but I never really understood how I got it working... and last time, I was using it via a popup window as opposed to an...
3
by: mikeorb | last post by:
Is there a way to determine the object that a property is in? For example: function MyClass() { ... } MyClass.prototype.myFunc = function() { ... } var obj = new MyClass(); var sameobj =...
7
by: w.monthard | last post by:
Hi, here is my trouble: I need to call 2 différents processes in a same dos window, the first one is needed for the 2nd, and I have to pass several different arguments to the 2nd. My problem...
3
by: Rob Nicholson | last post by:
How do you determine if a program is running in the Visual Studio IDE/debugger as opposed to standalone? We often include support files in the same folder as the executable and would so something...
0
by: han zhiyang | last post by:
I've just studied the "how to" web service and the async pattern in donnet.I make a test with these knowledges,but I got a strange result. Here is my test. 1.Write a simple "Add" service named...
2
by: stevie.greenslade | last post by:
'Lo all. I have a simple question I'd like help on. :] How, if at all, would one go about suppressing the console window that flashes up when you make at system() call in your C++ program? I'm...
7
by: semedao | last post by:
Hi all, I view many posts about this issue , the connected property does not tell us the current status of the socket. based on couple of suggestions of msdn , and some article here , I try to...
2
by: Rob Dob | last post by:
How do I determine if there are any rows within the BindingSource that have changed prior to calling the EndEdit(). I need to do this in order to archive some records and if I call the EndEdit()...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.