473,396 Members | 1,722 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,396 software developers and data experts.

Detect if compiling as a console application


Is there anyway the VB Compiler can detect if a program is a console
application? I have some libraries that need to write to the console if
the program is a console app.

Thanks,
Mike Ober.

May 19 '06 #1
4 2214
can't you just call System.Console.WriteLine("") anyway? If the app is
a console app, the line will be written to it, otherwise they will not.

May 19 '06 #2
What Chris describes is my experience. I use it alot for throwing
stuff to console that helps me debug. There is a noticable performance
hit though, and I wonder, if the console is not enabled, and a
Console.WriteLine call is made, what happens? Is there some sort of
buffer or resource that the text still writes to? I've never tested
the performance of writing to console when there is no console, as I
only do this when compiled as DEBUG, using conditional compilation
statements.

May 20 '06 #3
> What Chris describes is my experience. I use it alot for throwing
stuff to console that helps me debug. There is a noticable performance
hit though, and I wonder, if the console is not enabled, and a
Console.WriteLine call is made, what happens? Is there some sort of
buffer or resource that the text still writes to? I've never tested
the performance of writing to console when there is no console, as I
only do this when compiled as DEBUG, using conditional compilation
statements.


Maybe System.Windows.Forms.Application.MessageLoop will help decide the
issue at runtime. It returns true if there a message loop is running on the
current thread. So, if your app is single threaded, then it should tell the
difference between a console app and a windows app. Multi-threading
complicates things - a worker thread in a windows app cant effectively use
it. Also, I don't know what it does in other settings, eg a service.

The compiler /target option is what really decides the issue. So the answer
to the original question is yes - the compiler knows about /target. But I
couldn't find out how to access it or an equivalent at compile time (eg via
#if) or run time.
May 20 '06 #4
You get an IOException error if you don't have a console. My current
workaround is as follows:

public sub WriteLog(byval msg as string)
static isConsole as boolean = true
debug.print(msg)
logs.WriteLog(msg) ' Logs is always declared and ready to use
if not isConsole then return
try
Console.Writeline(msg)
catch ex as exception
isConsole = false
end try
end sub

Still a small performance hit (testing a local static variable), but not the
major performance hit everytime it's called.

Mike.
"Snozz" <sh******@cs.fsu.edu> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
What Chris describes is my experience. I use it alot for throwing
stuff to console that helps me debug. There is a noticable performance
hit though, and I wonder, if the console is not enabled, and a
Console.WriteLine call is made, what happens? Is there some sort of
buffer or resource that the text still writes to? I've never tested
the performance of writing to console when there is no console, as I
only do this when compiled as DEBUG, using conditional compilation
statements.


May 20 '06 #5

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

Similar topics

5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
7
by: Clint Herron | last post by:
Howdy! I posted this question on CSharpCorner.com, but then realized I should probably post it on a more active newsgroup. This will be my only cross-post. I'm creating a game engine, and...
4
by: sanjana | last post by:
hi can anyone help me with this i want to write a code in c#.net which detects usb storage and media card insertion can anyone help me with this?? thanx
6
by: sanjana | last post by:
hi i wanna detect if a anything is connected to the usb port I am using system.management class for tht purpose this is my code class usbdetect { public static void Main() { usbdetect we =...
12
by: Markus Ewald | last post by:
I'm just experimenting around with the VisualC++ 2005 Express Edition Beta and found some strange behavior for which I can't seem to find a workaround. What I've done is set up two static library...
8
by: BJ | last post by:
Problem: How can I code up a client side process to detect if the network is available? Synopsis: I am writing ASP.NET input forms for a Panasonic Tuff book. The users will be walking around...
1
by: CeciMar | last post by:
I'm new to vb.net and I have a very simple console application. When I attempt to compile it at the command prompt I get error BC30420 Sub Main not found. I know the namespace and module name but...
0
by: Ontrace | last post by:
hello, I have Problem with Client Server Application when I unplug the client network cable, the server still read the network stream what function should I use to make server detect that the...
3
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi all mister, Which is THE BEST WAY IN THE WORLD AROUND for: 1. detect Network
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.