473,785 Members | 2,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1969
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*****@charte r.net> wrote in message
news:10******** *****@corp.supe rnews.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****@communi ty.nospam> wrote in message
news:OA******** ******@TK2MSFTN GP11.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*****@charte r.net> wrote in message
news:10******** *****@corp.supe rnews.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.Http Application.Err or event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomai n.UnhandledExce ption event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows. Forms.Applicati on.ThreadExcept ion 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.Thr eadException 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.Thr eadException 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.Unhan dledException 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.Thr eadException and possible the
AppDomain.Unhan dledException (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*****@charte r.net> wrote in message
news:10******** *****@corp.supe rnews.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
4557
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 IFRAME. I've got several months of javascript under my belt and can resolve most things without errors in my Mozilla Javascript Console, but this one just does not do it for me. This is the picture:
3
1706
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 = SOMEFUNCTION(obj.myFunc); So my goal is to get a reference to the object by just having the
7
1831
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 is that there are as many dos windows as calls to "myProcess.start()", and I don't know how to do ... Anybody has an idea ?
3
2770
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 like: Dim SupportFile As String SupportFile = Application.StartupPath & "\SupportFile.txt" But of course this fails when running in the IDE as the executable is in the BIN folder so we need to do something like this:
0
1366
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 MathWS( the class name),and put it in a ..asmx file named math.asmx in the "D:/winnt/interpub/wwwroot/mathws" directory. "mathws" is my new-built directory. 2.run the http://localhost/mathws/math.asmx,find it works well,and run run the...
2
2384
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 using Dev-C++ with GTK-- with all the 'GUI' options ticked. There is nothing functionally wrong with the program save this flashing console window.
7
16944
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 write an helper method that will tell if the socket is connected or not , but it's not working good continue to tell me that the socket is connectedeven if the other party already call shutdown(both) + close , or , even if the other party close the...
2
11888
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() then it also wipes out the orginal version of the dataset record with the proposed changes., However I don't wish to iterate through every row in the dataset in order to figure out changes, Does the BindingSource not have something similar to the...
10
7000
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 MyEnumWindowsProc(HWND hwnd, LPARAM lparam) {
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10327
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.