If you want to keep reading the value of a property (10 seconds) that
keeps changing,
how would you do it. I tried this, but it did not work
Thread th = new Thread(new ThreadStart(ReadMe));
th.Start();
Thread.Sleep(3000);
th.Abort();
Thread.Sleep(1000); 12 6161
JPSutor,
I wouldn't use a polling mechanism like this. Rather, I would have some
sort of notification on class which indicates when the property changes.
The framework has a standard for things like this.
The first (pre .NET 2.0) is to have an event on your class named
<property name>Changed. This event is of type EventHandler, and you fire it
when the event changes.
If you are using .NET 2.0, you should use the INotifyPropertyChanged
interface to indicate when a property changed (it's more efficient in
general than the old method).
If you want to poll the property, then I would use a timer, instead of
causing a thread to sleep, and check the property value there.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"JPSutor" <jp*****@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... If you want to keep reading the value of a property (10 seconds) that keeps changing, how would you do it. I tried this, but it did not work
Thread th = new Thread(new ThreadStart(ReadMe)); th.Start(); Thread.Sleep(3000); th.Abort(); Thread.Sleep(1000);
I might also add that a while loop with a sleep duration works quite
well. I noticed in pre .Net 2.0 the timer just wasn't reliable enough
in certain situations. A while loop seemed to work well as an alternate
solution.
Nicholas Paldino [.NET/C# MVP] wrote: JPSutor,
I wouldn't use a polling mechanism like this. Rather, I would have some sort of notification on class which indicates when the property changes. The framework has a standard for things like this.
The first (pre .NET 2.0) is to have an event on your class named <property name>Changed. This event is of type EventHandler, and you fire it when the event changes.
If you are using .NET 2.0, you should use the INotifyPropertyChanged interface to indicate when a property changed (it's more efficient in general than the old method).
If you want to poll the property, then I would use a timer, instead of causing a thread to sleep, and check the property value there.
Hope this helps.
Hi, Thread th = new Thread(new ThreadStart(ReadMe)); th.Start(); Thread.Sleep(3000); th.Abort(); Thread.Sleep(1000);
This does not work cause Thread.Sleep refer to the current thread , the
thread where the method is called, for this to work Thread.Sleep should be
in the ReadMe() method.
No need to call Abort btw.
ITOH, I would not do it this way, I would use a timer .
Or even better an event.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Nicholas,
What I am trying to accomplish is this.
I have a form with a progress bar on it.
When I make a call to a method in another class to iterate through a
recordset, I want the progress bar to show the progress.
When I try referencing the form from my class I get an error message.
What I'm trying to do here is to set a property value and read it in
each time the timer fires. I realize this isn't the most effecient
method, but my first try did not work
Nicholas,
What I am trying to accomplish is this.
I have a form with a progress bar on it.
When I make a call to a method in another class to iterate through a
recordset, I want the progress bar to show the progress.
When I try referencing the form from my class I get an error message.
What I'm trying to do here is to set a property value and read it in
each time the timer fires. I realize this isn't the most effecient
method, but my first try did not work
Nicholas,
What I am trying to accomplish is this.
I have a form with a progress bar on it.
When I make a call to a method in another class to iterate through a
recordset, I want the progress bar to show the progress.
When I try referencing the form from my class I get an error message.
What I'm trying to do here is to set a property value and read it in
each time the timer fires. I realize this isn't the most effecient
method, but my first try did not work
Nicholas,
What I am trying to accomplish is this.
I have a form with a progress bar on it.
When I make a call to a method in another class to iterate through a
recordset, I want the progress bar to show the progress.
When I try referencing the form from my class I get an error message.
What I'm trying to do here is to set a property value and read it in
each time the timer fires. I realize this isn't the most effecient
method, but my first try did not work
Nicholas,
What I am trying to accomplish is this.
I have a form with a progress bar on it.
When I make a call to a method in another class to iterate through a
recordset, I want the progress bar to show the progress.
When I try referencing the form from my class I get an error message.
What I'm trying to do here is to set a property value and read it in
each time the timer fires. I realize this isn't the most effecient
method, but my first try did not work
Nicholas,
What I am trying to accomplish is this.
I have a form with a progress bar on it.
When I make a call to a method in another class to iterate through a
recordset, I want the progress bar to show the progress.
When I try referencing the form from my class I get an error message.
What I'm trying to do here is to set a property value and read it in
each time the timer fires. I realize this isn't the most effecient
method, but my first try did not work
Nicholas,
What I am trying to accomplish is this.
I have a form with a progress bar on it.
When I make a call to a method in another class to iterate through a
recordset, I want the progress bar to show the progress.
When I try referencing the form from my class I get an error message.
What I'm trying to do here is to set a property value and read it in
each time the timer fires. I realize this isn't the most effecient
method, but my first try did not work
Nicholas,
What I am trying to accomplish is this.
I have a form with a progress bar on it.
When I make a call to a method in another class to iterate through a
recordset, I want the progress bar to show the progress.
When I try referencing the form from my class I get an error message.
What I'm trying to do here is to set a property value and read it in
each time the timer fires. I realize this isn't the most effecient
method, but my first try did not work
I suppose that the error message you've got is about thread synchronization.
If so, try this :
public class YourForm : System.Windows.Forms.Form
{
private delegate void ProgressBarDelegate(Int32 floodPercent);
public void UpdateProgressBar(Int32 floodPercent)
{
// Need thread synchronization ?
//
if (this.InvokeRequired)
{
this.Invoke(
new ProgressBarDelegate(this.UpdateProgressBar),
floodPercent);
return;
}
// Update ProgressBar flood percent here...
}
}
public class YourWorkingThread
{
private YourForm parentForm;
private DataTable dataToProceed;
YourWorkingThread(YourForm parentForm, DataTable dataToProceed)
{
this.parentForm = parentForm;
this.dataToProceed = dataToProceed;
}
public void ThreadedJob()
{
Int32 rowCount = dataToProceed.Rows.Count;
for (Int32 i = 0; i < rowCount; i++)
{
// Proceed dataToProceed.Rows[i] ...
// Update progress bar
//
if (i % 100 == 0)
parentForm.UpdateProgressBar((Int32)((Double)i / rowCount + 0.5));
}
}
}
"JPSutor" wrote: Nicholas, What I am trying to accomplish is this. I have a form with a progress bar on it. When I make a call to a method in another class to iterate through a recordset, I want the progress bar to show the progress. When I try referencing the form from my class I get an error message. What I'm trying to do here is to set a property value and read it in each time the timer fires. I realize this isn't the most effecient method, but my first try did not work
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anthony Baxter |
last post by:
On behalf of the Python development team and the Python community, I'm
happy to announce the release of Python 2.3.1 (final).
Python 2.3.1 is a pure bug fix release of Python 2.3, released in...
|
by: news.microsoft.com |
last post by:
Hi,
Currently I have a thread thats spinning and doing a
Thread.Sleep(someTime).
I was thinking of changing this to Thread.Sleep(Timeout.Infinite); then
when I have actual data in a...
|
by: Cider123 |
last post by:
I ran into a situation where my Window Service had to process 100,000+
files, when I first noticed I needed to tweak various routines.
Everything runs fine, but here's what I ran into:
In the...
|
by: Matthew Groch |
last post by:
Hi all,
I've got a server that handles a relatively high number of concurrent
transactions (on the magnitude of 1000's per second). Client
applications establish socket connections with the...
|
by: Matthijs |
last post by:
Hi,
I have a problem coding a UDP Server/client. The server needs to send big
amounts of data over UDP. The problem however is that you can't send as fast
as you like. (All packets will be dropped...
|
by: Chris Dunaway |
last post by:
According to the docs, calling Thread.Sleep(0) causes the thread to be
"suspended to allow other waiting threads to execute."
What happens if I call Thread.Sleep(500)? Do other threads not get a...
|
by: k.mellor |
last post by:
Hi,
I hope someone can help. I have written a simple form to demonstrate
my problem/question. The code follows.
The form starts a thread, which using delegates updates a label (Every
second...
|
by: Buckaroo Banzai |
last post by:
Hello, newbie here...
I'm writing this program but when I click the start button which should initiate either the Hare or the Tortoise, it does not, this is the first time I use threads, so the...
|
by: =?Utf-8?B?anAybXNmdA==?= |
last post by:
I've got a routine that builds a table using different queries, different SQL
Tables, and adding custom fields.
It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the
table...
|
by: Steve |
last post by:
Hi All,
I've been trying to come up with a good way to run a certain process
at a timed interval (say every 5 mins) using the SLEEP command and a
semaphore flag. The basic thread loop was always...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |