473,749 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events in Console programs?

Can console programs do events? Or are they strictly linear programs?
Nov 21 '05 #1
8 5849
>Can console programs do events?

Yes

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
Okay...where can I find some example code? I haven't tried anything yet,
but I want to spawn a couple of threads from Sub Main and let them generate
the events. Do I need to keep Sub Main active (with a loop or something) to
keep the program from exiting?

"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:ev******** ********@TK2MSF TNGP09.phx.gbl. ..
Can console programs do events?


Yes

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 21 '05 #3
Terry,
Okay...where can I find some example code?
I can't think of any that demonstrates exactly this, sorry.

I haven't tried anything yet,
but I want to spawn a couple of threads from Sub Main and let them generate
the events.
You generate events the same way regardless which type of executable
you're creating.

Do I need to keep Sub Main active (with a loop or something) to
keep the program from exiting?


Yes.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4
Piece of cake - to demonstrate write a console application that spawns some
child threads. Immediately after spawning the threads - make a call to
Application.Run () which will start a new standard application message loop
(without a form object) and prevent your console application for immediately
terminating as would a typical console app.

Brain Patterson
http://dotnet.redeyepos.com

"Terry Olsen" <to******@hotma il.com> wrote in message
news:OK******** ********@TK2MSF TNGP09.phx.gbl. ..
Can console programs do events? Or are they strictly linear programs?

Nov 21 '05 #5
Terry,

You mean something as this?

\\\
Module Module1
Private running As Boolean = True
Private WithEvents tim As New System.Timers.T imer
Sub Main()
tim.Enabled = True
tim.Interval = 3000
Do While running
Console.Write(" I am waiting" & vbCrLf)
Loop
End Sub
Private Sub tim_Elapsed(ByV al sender As Object, _
ByVal e As System.Timers.E lapsedEventArgs ) Handles tim.Elapsed
running = False
End Sub
End Module
///
I hope this helps a little bit?

Cor
Nov 21 '05 #6
"Terry Olsen" <to******@hotma il.com> schrieb:
Okay...where can I find some example code? I haven't tried anything yet,
but I want to spawn a couple of threads from Sub Main and let them
generate the events. Do I need to keep Sub Main active (with a loop or
something) to keep the program from exiting?

Add a reference to 'System.Windows .Forms.dll', import the
'System.Windows .Forms' namespace, and call 'Application.Ru n' at the end of
your 'Sub Main'. Then you can call 'Application.Ex itThread' to quit the
application.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
Cor,

"Cor Ligthert" <no************ @planet.nl> schrieb:
Do While running
Console.Write(" I am waiting" & vbCrLf)
Loop


Notice that this busy waiting loop will cause large CPU utilization :-(.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #8
Herfried,
Notice that this busy waiting loop will cause large CPU utilization :-(.


Why, in this sample it is very busy showing lines to the console and that
takes CPU time, you cannot prevent that. However you can do beside it very
simple something else.

Maybe it is time you get a new computer.

It is not meant as a real application, however to show how to use an event
in a console application.

There can of course be build in any wait, to show the most simple one in
this case.
Threading.threa d.sleep(1000).

However it is not a real application only to show that an event is possible.

Therefore I don't understand what you mean?

Cor

Nov 21 '05 #9

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

Similar topics

1
3002
by: Will Stuyvesant | last post by:
I never used the popen or popen2 libraries but it is my understanding that they can capture the output of console based programs. Is it also possible to send keystrokes to console base programs? I would like to program a Python program that can play for instance the tty version of nethack 3.4.3 on Windows, simulating a human player: for nethack it would not be possible to know if a human or a computer program is playing it. It is a...
14
12142
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming years namespace MyNamespac public delegate void MyDel() public class MyBase public virtual...
2
19012
by: Gulshan Oshan | last post by:
I want to implement a simple console that continuously listens for an event from a custom object. I am unable to capture the events from the object. If I subscribe to the events in a windows app it works fine. Any idea? using System; using MyTestApp.Messaging; using MyTestApp.BusinessLayer; using System.Threading;
2
1632
by: _R | last post by:
I've got a few apps that were designed to be used via MSDOS window. They make use of the old-style VC++6 Console class for doing writes, cursor repositioning, scrolling, etc. (Unfortunate name clash with the new .NET console class, so it's tough to search for info). Has anyone written a C# or C++ wrapper for the old Console class or something that can be used under .net?
3
5668
by: Crucifix | last post by:
Hello, I'm writing a small C# app, and part of what I'm trying to do involves the dragging of PictureBox controls on a form. Unfortunately, MouseMove seems to be behaving very oddly, causing spurious MouseMove events when the cursor doesn't actually move. I've looked for a solution in the groups, and although I've come close, I haven't found a proper explanation or fix. Here is a rundown, followed by a very simple test app that...
3
1595
by: Chris | last post by:
Hi, what is the difference between using events and delegates (apart from the syntax) ? have a look at following (working) programs please (you can just copy/paste and build it) : First program uses delegates, the second events but both do inherently the same :
0
2532
by: guyarkam | last post by:
I have the following code in which I use events to read on eth or serial port when data commes in. The ASCHFProtLib library is a third party library that I have to use as it is. Unfortunately this version of my code does not work. It seems that the events are not triggering when there is a data on any of the eth or serial ports. Basicaly all the events handler functions (OnMsgRecv and similar) are not executed. I have included a piece of...
1
1252
by: =?Utf-8?B?TWF0Y29u?= | last post by:
Hello, I'm pretty new to asp.net programming and to these forums, so I hope that I'm asking an appropriate question in the right place. I'm helping to develop a web application in asp.net 2.0, vb.net, and I'm trying to execute code every 10 minutes, starting at 6:00 am and ending at 10:00 am, every Monday thru Friday. Those exact times are rough examples, and may change. So I think I need to create some kind of timer that fires an...
27
2966
by: CarlosMB | last post by:
Hello, I am writing code that uses a DLL which is supposed to print to console some useful information but for some reason it is not doing so. The environment is a bit complex to explain but here it goes: - I am using a C library called SYMPHONY, which I compiled myself. When using that
0
8997
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
9568
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
9389
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...
1
9335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6801
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4709
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...
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.