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

Events in Console programs?

Can console programs do events? Or are they strictly linear programs?
Nov 21 '05 #1
8 5828
>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.org> wrote in message
news:ev****************@TK2MSFTNGP09.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******@hotmail.com> wrote in message
news:OK****************@TK2MSFTNGP09.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.Timer
Sub Main()
tim.Enabled = True
tim.Interval = 3000
Do While running
Console.Write("I am waiting" & vbCrLf)
Loop
End Sub
Private Sub tim_Elapsed(ByVal sender As Object, _
ByVal e As System.Timers.ElapsedEventArgs) Handles tim.Elapsed
running = False
End Sub
End Module
///
I hope this helps a little bit?

Cor
Nov 21 '05 #6
"Terry Olsen" <to******@hotmail.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.Run' at the end of
your 'Sub Main'. Then you can call 'Application.ExitThread' 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.thread.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
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? ...
14
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...
2
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...
2
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...
3
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...
3
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...
0
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...
1
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,...
27
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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.