473,881 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't get Timer to work with StreamReader.

I have a program which is constantly reading from a stream and what I'm
wanting to do is, if the stream hasn't sent anything after a certain amount
of time then do something. I've tried doing this like this...

while(!done)
{
idleTimer.Start ();
response = streamReader.Re adLine();
idleTimer.Stop( );
....

The interval on the Timer is set to 10000 (10 seconds) but I've hung
response = streamReader.Re adLine() for five minutes and it still doesn't run
the Timer's Tick event. The interesting thing though, is if I do this...

idleTimer.Start ();
MessageBox.Show ("Testing... ");
response = streamReader.Re adLine();
idleTimer.Stop( );

....and then don't press the button on the message box, after 10 seconds the
Tick event is fired. So why not after 10 seconds of waiting for a response
from the stream? I've even tried sticking the timer stuff in it's own thread
but I get the same problem.

Please help,

Darrell

Nov 16 '05 #1
3 2150
My guess is that the StreamReader.Re adLine method hangs the current
thread, which prevents it from pumping messages. MessageBox.Show keeps
pumping messages while the message box is displayed, and that lets the
timer messages be handled.

You could perhaps put the StreamReader code in a worker thread, keep the
timer on the ui thread, and when the timer fires check if anything has
been read.

Regards,
Joakim
redneon wrote:
I have a program which is constantly reading from a stream and what I'm
wanting to do is, if the stream hasn't sent anything after a certain amount
of time then do something. I've tried doing this like this...

while(!done)
{
idleTimer.Start ();
response = streamReader.Re adLine();
idleTimer.Stop( );
...

The interval on the Timer is set to 10000 (10 seconds) but I've hung
response = streamReader.Re adLine() for five minutes and it still doesn't run
the Timer's Tick event. The interesting thing though, is if I do this...

idleTimer.Start ();
MessageBox.Show ("Testing... ");
response = streamReader.Re adLine();
idleTimer.Stop( );

...and then don't press the button on the message box, after 10 seconds the
Tick event is fired. So why not after 10 seconds of waiting for a response
from the stream? I've even tried sticking the timer stuff in it's own thread
but I get the same problem.

Please help,

Darrell

Nov 16 '05 #2
I've tried putting the timer stuff in a new thread but I still get the same
problem. The method with the reader in is a thread off the UI in itself
already.

Darrell

"Joakim Karlsson" wrote:
My guess is that the StreamReader.Re adLine method hangs the current
thread, which prevents it from pumping messages. MessageBox.Show keeps
pumping messages while the message box is displayed, and that lets the
timer messages be handled.

You could perhaps put the StreamReader code in a worker thread, keep the
timer on the ui thread, and when the timer fires check if anything has
been read.

Regards,
Joakim
redneon wrote:
I have a program which is constantly reading from a stream and what I'm
wanting to do is, if the stream hasn't sent anything after a certain amount
of time then do something. I've tried doing this like this...

while(!done)
{
idleTimer.Start ();
response = streamReader.Re adLine();
idleTimer.Stop( );
...

The interval on the Timer is set to 10000 (10 seconds) but I've hung
response = streamReader.Re adLine() for five minutes and it still doesn't run
the Timer's Tick event. The interesting thing though, is if I do this...

idleTimer.Start ();
MessageBox.Show ("Testing... ");
response = streamReader.Re adLine();
idleTimer.Stop( );

...and then don't press the button on the message box, after 10 seconds the
Tick event is fired. So why not after 10 seconds of waiting for a response
from the stream? I've even tried sticking the timer stuff in it's own thread
but I get the same problem.

Please help,

Darrell

Nov 16 '05 #3
redneon... I just finished a sample project that launches I/O threads
and calls WaitForThreadEx it(waitForThrea dTime). Basically, each I/O
thread callsback when done. The worker thread sleeps in a loop checking
to see if the I/O thread has returned. If the waitForThreadTi me is
exceeded the worker thread exits the loop.

http://www.geocities.com/jeff_louie/call_console.htm

Regards,
Jeff
I've tried putting the timer stuff in a new thread but I still get the

same problem.<

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

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

Similar topics

5
5094
by: Dhilip Kumar | last post by:
Hi all, I have developed a windows service using the windows service project template in VS.NET. I have used three controls in the service, a timer, performance counter and a message queue control. The service will "sleep" for 'n' seconds using the timer control and whenever the timer_elapsed event occurs, I use the performance counter object to determine availability of few resources. Based on the availability of resources, I use the...
8
1845
by: Jim Hammond | last post by:
The following code tries to excute a function 10 seconds after Page_Load by using a Timer, but the callback never gets called. private void Page_Load(object sender, System.EventArgs e) { // Set timer to call Page_PostLoad in 10 seconds
6
2065
by: Antti Laakso | last post by:
Hi i have function like above Public Sub halytystutkinta() Dim ds As New DataSet ds = dl2.HaeHalytys() Dim onkohal As Int16 onkohal = ds.Tables(0).Rows(0).Item("onkohalytys") halid = ds.Tables(0).Rows(0).Item("halid")
4
1590
by: Martin Hill | last post by:
Hi there, How can I find the components added to web form from my custom web control? Suppose I added a Timer component (with name "timer1") onto the web form, from my user web control, how can I locate the timer component by name "timer1"? The Page.Controls collection only contains web controls but no components.
2
2609
by: Noggin The Nog | last post by:
Hi all, I've been trying to get HttpWebResponse to work, but whenever I try I get "The operation has timed-out". I'm simply trying to send an HTTP request querystring to a remote website and read back the single string it returns (OK/Not-Ok)! It seems such a simple thing to do, but I've been on this for hours now! Here's the code I'm trying: Dim myRequest As HttpWebRequest Dim myResponse As HttpWebResponse
12
1489
by: Crirus | last post by:
Hi! I havea control that display messages... I added a timer to it Every time a noew mesaage should be displayed I do the following: Private sub ShowMsg(message as string) Me.lblStatus.Text = message tmrStatus.Start() tmrStatus.Interval = 3000
16
4018
by: les | last post by:
I'm trying to http post xml data to a remote server and I get this error: BC30518: Overload resolution failed because no accessible 'GetBytes' can be called with these arguments: Line 20: Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream) The aspx page is shown below. Can anyone help?
4
1922
by: Lemune | last post by:
Hello everyone. I'm using vb 2005. I'm creating program that run as service on windows. And in my program I need to use timer, so I'm using timer object from component. I try my source code on another project that use windows form and it work. But when I implement my source code on my program that run as service on windows (I have change the code so it would work on service but I still use timer object from component), and it doesn't...
16
3261
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not do it. If I bring this same code outside this event handler, it works just fine. Is this normal?
0
9776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11105
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...
1
10827
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
10403
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
9556
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...
0
7113
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
5978
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4599
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
3
3226
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.