473,508 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading

Hi All,

I need help with the following: Using VB.NET 2005, I am building a
custom class in a separate assembly. The purpose of this class is to poll
the internet to determine connectivity. I have that part functioning
properly using HTTPRequest and HTTPResponse.

The problem lies here: I'd like to execute this monitoring on an
interval (Ex.: every 5 minutes), to get an up-to-date status. This updated
status would then be propagated to the class/service/app. that instanced my
class, which in my case is a WinForms application, but it can be a Windows
Service, or console app. etc...

I am trying to use the System.Threading.Thread class as from what I have
read, the other 2 types of timers are not really be usable in my situation:
System.Timers.Timer and System.Forms.Timer. I may be wrong on the
System.Timers.Timer, but the System.Forms.Form one, I am sure of this.

What is the best approach to get status data out of my custom class to
the calling app. without cross threading issues (which I am currently
experiencing when I try to transfer info to my WinForms app.). Furthermore,
should I be starting and stopping the timer while I actually perform the
polling, etc...?

Regards,

Giovanni P.

Mar 14 '06 #1
4 2467
Giovanni,

I have read the same as you. My experience is however that for a simple
application the system.forms.form timer is the best (and because that you
are polling one time in 5 minutes in my idea more than sufficient)..

For windowservices is the System.Timers.Timer
for worker threads the threading.timer

The last two work on there own threads and are therefore not as easy to
abort as the first mentioned one. Don't forget for smooth use to disable the
timer if you enter its elapsed event and to enable it again if you leave
it.

I hope this helps,

Cor

"Giovanni" <Gi******@discussions.microsoft.com> schreef in bericht
news:0A**********************************@microsof t.com...
Hi All,

I need help with the following: Using VB.NET 2005, I am building a
custom class in a separate assembly. The purpose of this class is to poll
the internet to determine connectivity. I have that part functioning
properly using HTTPRequest and HTTPResponse.

The problem lies here: I'd like to execute this monitoring on an
interval (Ex.: every 5 minutes), to get an up-to-date status. This
updated
status would then be propagated to the class/service/app. that instanced
my
class, which in my case is a WinForms application, but it can be a Windows
Service, or console app. etc...

I am trying to use the System.Threading.Thread class as from what I
have
read, the other 2 types of timers are not really be usable in my
situation:
System.Timers.Timer and System.Forms.Timer. I may be wrong on the
System.Timers.Timer, but the System.Forms.Form one, I am sure of this.

What is the best approach to get status data out of my custom class to
the calling app. without cross threading issues (which I am currently
experiencing when I try to transfer info to my WinForms app.).
Furthermore,
should I be starting and stopping the timer while I actually perform the
polling, etc...?

Regards,

Giovanni P.

Mar 14 '06 #2
Hi Cor,

Thanks for the info? I was just curious as to whether to disable my
timer, do the work, and re-enable my timer; which is what you have confirmed.
I guess my last issue is still deciding whether to use the
System.Forms.Timer or the System.Timers.Timer as you will recall that I am
going to be using this functionality from a class in a separate assembly
which for the moment is only being called by a WinForms app, but would be
implemented in Console or Service type contexts.

Regards,

Giovanni

"Cor Ligthert [MVP]" wrote:
Giovanni,

I have read the same as you. My experience is however that for a simple
application the system.forms.form timer is the best (and because that you
are polling one time in 5 minutes in my idea more than sufficient)..

For windowservices is the System.Timers.Timer
for worker threads the threading.timer

The last two work on there own threads and are therefore not as easy to
abort as the first mentioned one. Don't forget for smooth use to disable the
timer if you enter its elapsed event and to enable it again if you leave
it.

I hope this helps,

Cor

"Giovanni" <Gi******@discussions.microsoft.com> schreef in bericht
news:0A**********************************@microsof t.com...
Hi All,

I need help with the following: Using VB.NET 2005, I am building a
custom class in a separate assembly. The purpose of this class is to poll
the internet to determine connectivity. I have that part functioning
properly using HTTPRequest and HTTPResponse.

The problem lies here: I'd like to execute this monitoring on an
interval (Ex.: every 5 minutes), to get an up-to-date status. This
updated
status would then be propagated to the class/service/app. that instanced
my
class, which in my case is a WinForms application, but it can be a Windows
Service, or console app. etc...

I am trying to use the System.Threading.Thread class as from what I
have
read, the other 2 types of timers are not really be usable in my
situation:
System.Timers.Timer and System.Forms.Timer. I may be wrong on the
System.Timers.Timer, but the System.Forms.Form one, I am sure of this.

What is the best approach to get status data out of my custom class to
the calling app. without cross threading issues (which I am currently
experiencing when I try to transfer info to my WinForms app.).
Furthermore,
should I be starting and stopping the timer while I actually perform the
polling, etc...?

Regards,

Giovanni P.


Mar 14 '06 #3
I would maybe try to put the thread to sleep instead, for 5 minutes.

When it awakens, perform the processing, then put it back to sleep.

This is probably a better way to handle this.

If you only have one thread then you might want to look at calling your
other assembly asynchronously with delegates, this way you can have a
callback method in your winforms app, otherwise to pass parameters back
to your winforms app, you will have to enforce thread safety and check
if InvokeRequired before modifying data on your winforms app. It
depends on how often and at what point you will be passing data back
and forth.

Mar 14 '06 #4
Dkode,
I would maybe try to put the thread to sleep instead, for 5 minutes.

When it awakens, perform the processing, then put it back to sleep.
What is the advantage from that in your opinion. I don't see it.

I see a disadvantage, AFAIK you cannot cancel the program because it does no
events.

Cor

This is probably a better way to handle this.

If you only have one thread then you might want to look at calling your
other assembly asynchronously with delegates, this way you can have a
callback method in your winforms app, otherwise to pass parameters back
to your winforms app, you will have to enforce thread safety and check
if InvokeRequired before modifying data on your winforms app. It
depends on how often and at what point you will be passing data back
and forth.

Mar 14 '06 #5

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

Similar topics

65
6663
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
2
2954
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
77
5208
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
6
555
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine , but final process (3) doesnt get called. i stop and restart the windows service...
2
2231
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True...
11
4989
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found...
17
6389
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
0
1569
by: kingcrowbar.list | last post by:
Hello Everyone I have been playing a little with pyGTK and threading to come up with simple alert dialog which plays a sound in the background. The need for threading came when in the first...
7
2351
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
126
6609
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
7227
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,...
0
7127
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
7331
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
7391
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
7501
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...
0
5633
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,...
1
5056
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...
0
4713
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...
0
1564
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 ...

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.