Multithreading With A Timer?
Mar 1, 2011
I have a screen that checks for alerts every 30 seconds by looking up outstanding issues from a database.When there is an alert, an audio file is played depending on the alert.It takes 1-2 seconds to grab this audio file which caused an issue with global screen freezing, so I added multithreading where it plays the sound file. This seemed to work fine.However I am new to multithreading and am not sure if I'm working with it efficiently..I have simply declared the sound-playing function as a thread at the top:[code]I am unsure if starting and aborting the thread is the right way to do it. However if I suspend or make the thread sleep I would have to determine whether it has been run before.
View 18 Replies
ADVERTISEMENT
Jul 14, 2011
I recently switched my code from using the windows.forms.timer to the systems.timer.timer and it has resulted in a multithreading error. I'm using the timer to trigger just one event so multithreading shouldn't be an issue. To give more detail I have implemented the timer at follows:
At the top of the class I have: Private Shared timr1sec As System.Timers.Timer
When the program loads (Private Sub Test_load):
timr1sec = New System.Timers.Timer(1000)
AddHandler timr1sec.Elapsed, AddressOf OnTimedEvent
In OnTimedEvent I call several subroutines, and write some data to the screen using a ListView object.VisualExpress throws the multithreading error on the last line of this code, which is in OnTimedEvent
[Code]...
View 1 Replies
Feb 29, 2012
I've got a vb app in .Net 4 that i'm working on. The app fires up dynamic threads to run some jobs. Each thread runs a certain job and within that thread, it performs a infinate loop. It needs to be this way, i can't have the thread and then begin again...
anyway.. i was using threading.thread.sleep in the loop to have the loop pause for a bit before running again. It seems that this is not a good way to go and not recommended. So i thought perhaps i could use a dynamic timer or something else to have the thread wait for say 30 seconds before running again. i was hoping someone could give me some direction and example code.[CODE...]
View 1 Replies
Aug 2, 2010
What I need to do to make this code work for hours as well?[code]...
View 6 Replies
Jan 15, 2009
I need an accurate timer to interface a Windows application to a piece of lab equipment.I used System.Timers.Timer() to create a timer that ticks every 10 msec, but this clock runs slow. For example 1000 ticks with an interval of 10 msec should take 10 wall-clock seconds, but it actually takes more like 20 wall-clock sec (on my PC). I am guessing this is because System.Timers.Timer() is an interval timer that is reset every time it elapses. Since it will always take some time between when the timer elapses and when it is reset (to another 10msec) the clock will run slow. This probably fine if the interval is large (seconds or minutes) but unacceptable for very short intervals.Is there a function on Windows that will trigger a procedure every time the system clock crosses a 10 msec (or whatever) boundary?
UPDATE: System.Timers.Timer() is extremely inaccurate for small intervals.I wrote a simple program that counted 10 seconds several ways:
Interval=1, Count=10000, Run time = 160 sec, msec per interval=16
Interval=10, Count=1000, Run time = 16 sec, msec per interval=15
Interval=100, Count=100, Run time = 11 sec, msec per interval=110
Interval=1000, Count=10, Run time = 10 sec, msec per interval=1000
It seems like System.Timers.Timer() cannot tick faster that about 15 msec, regardless of the interval setting.Note that none of these tests seemed to use any measurable CPU time, so the limit is not the CPU, just a .net limitation (bug?)For now I think I can live with an inaccurate timer that triggers a routine every 15 msec or so and the routine gets an accurate system time. Kinda strange, but...I also found a shareware product ZylTimer.NET that claims to be a much more accurate .net timer (resolution of 1-2 msec). This may be what I need. If there is one product there are likely others.
View 5 Replies
Jul 9, 2009
I have a timer on a page in ASP.NET.
After a certain period of time elapses, I want to disable the timer.
I want to put a static variable in the timers tick event that will track how many seconds have elapsed.
My question is, will this work?
If user X and Y are viewing the page will they both have separate local static variables?
What is the best method of shutting down an ASP.NET timer after a certain elapsed time?
View 1 Replies
Apr 23, 2009
I have a windows application that need to process som quite time consuming jobs. In my first try i did all processing under
the form thread. The result was bad response and update of the form due to the heavy jobs.To get around the problem with bad response from the form i created a new class "processing" where i put all the data processing. Then i instanciated a background worker where i in the "doWork" sub created a new instance of "processing".The "processing" class creates a timer from system.timer, and the timer drives the processing.On the Timer event Elapsed the timer starts a new thread from the thread pool.
My problem is now when i want to asynchronously close the background worker (with the corresponding function call what ever it is called ...) there is still a timer thread out there that causes exceptions for me.
1. How can i close my background worker and at the same time have the timer to be stopped?
2. Is there a way to synchronize the timer event so that the timer executes from the background worker thread?
3. Is there a better approach for me to adapt?
View 3 Replies
Jan 11, 2011
I want to create an array of timer in vb.net. My problem is that how will i raise the tick event for a particular timer, say mytimer(x).tick and inside the tick event there is also a button, say mybutton(x) which changes location every interval. for example:
public class blah
dim mybuttons(20) as button
dim mytimer(20) as timer
private sub form_load(....) handles me.load
for x as integer = 0 to 20
[Code]...
i dont know what to do next, all i want is to pass the button mybuttons(x) to mytimer(x) tick event, in which their index number are the same. i want to create one timer per button. how to do that? please help me and post example codes. i've researched the net but i cant understand passing variables, addhandlers, etc. i'm just new to programming object oriented.
View 6 Replies
Jul 4, 2011
How can I incorporate the timer so once a page loads the timer activates, waits a few seconds then I tell my program what to do next.I tried this code but it didnt work:
Timer1.Interval = 5000
Timer1.Enabled = True
Timer1.Start()
[code]....
View 3 Replies
Sep 30, 2010
Everything is nice and dandy on my pc, then I compile, move it to its final destination and I doesn't work! At first I thought it was a OS problem, but both machines has win7, I then thought it was a compilation problem, installed visual studio on the other pc, recompiled still with no luck, then it dawned on me, may it be a problem of 32bit vs 64bit?The piece of code is this:[code]....
By the way is not a problem of mouse_event, is the timer that doesn't work
View 2 Replies
Mar 24, 2009
I have a timer in vb.net and it's interval is 1000ms ,. i have placed in it's timer_tick event a code that will print screen the screen and save it to a database.The problem is when i click outside of the form, or loosing the focus of the mouse to the form containing that timer/printscreen, the timer stops. As a result the printscreen also stops.here are it's properties:
generate member = true
interval = 1000
modifiers = friend
View 1 Replies
Aug 13, 2010
I have a routine which is controlled by a timer. It works perfectly. The problem is that now, I need to run this routine several times, so I need to start differents threads so that my program doesn't get hung up. I've been trying to start my timer inside a thread, but it doesn't work!
View 18 Replies
Nov 6, 2009
VB6 create object of timer instead of timer control
View 5 Replies
Apr 6, 2009
Is it possible to use a timer to delay code? For example:
[code]...
View 7 Replies
Mar 15, 2009
I already created a button "enjoy button" that i want to move in a form when the "timer start button" is clicked.how do link the timer to the"timer start button" and make it move? this is what i tried so far..then am blank first
Quote:
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Me.xTimer.Enabled = False
xTimer.Interval = 10[code].........
View 21 Replies
Feb 24, 2011
In a vb 2010 project, I have 2 win forms: Form1 and Form2.
In the Form1 class there is a server-based timer: when the "elapsed event" fires, then I update the text of a Label1 on the Form2. A very simple code:
View 13 Replies
Jun 14, 2012
Quick question - if I have a timer set to 5000 (5 seconds) and the code in the timer takes longer than 5 seconds to run because of sql stuff, will the timer wait until the code is done till it fires again?
View 3 Replies
Jun 15, 2009
I'm wondering what exactly is the difference System.Timers.Timer and System.Windows.Forms.Timer???
View 4 Replies
Oct 27, 2009
My timer pauses (sort of the display portion (label) of the timer indeed pauses, however when the timer is resumed it starts again, but not at the point where it was disabled. As an example. If I pause the timer at 10:00 and wait ten seconds when I hit resume it starts at 09:50, where it should resume at 10:00 or 09:59
Module Helper
Public SessionTime As String
Public Pause As Boolean = False[code].....
View 3 Replies
Jan 18, 2010
What is multithreading and how do i do it in vb.net?
View 2 Replies
Dec 17, 2011
I am using an Application server for calling Oracle Reports and I have a URL to call the report. When the report is called the server converts it into PDF but when report contains large data it takes a lot of time to load. I want to do in asp.net that when I call the report url it opens the PDF file and copies it into the root of my web folder. The next time when I call the URL it opens the PDF file and creates a new PDF on backend for next call. I have made this function to download file
[Code]....
View 2 Replies
Mar 28, 2009
In which situations we can do the multithreading and deadlock concepts. can give some examples
View 4 Replies
Feb 27, 2011
Basically I am making a proxy testing program. A user can supply a list of proxies to test. What i want to be able to do is have them be able to specify how many threads they want to run. Then have the program go through the list testing each one using the amount of threads supplied. Really not sure even where to start on this. Threadpooling?
View 3 Replies
Dec 21, 2011
What does common data or data that's in a common, look and is treated by multithreading? I'm quite aware that acess to such data would have to be synchronized, but beyond that is it acessible?
"MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me
View 15 Replies
Apr 13, 2009
I have a class with a background worker in it that does some tasks on a separate thread. I want to fire some events from the background worker thread to the 'main thread' of the class, so that when using this class your not obliged to go make invoke calls for every event handler your using.I'm at a loss of how to do this though. When having a similar problem in a form of usercontrol I always use Me.Invoke, but this method is not present in a class inheriting system.object.
View 1 Replies
Aug 22, 2010
I have read many articles on multithreading over the past few days and so far I'm fairly comfortable with how it works. I am now working on my actual application, and have come across a few design issues that I'm hoping somebody has experience with.The basic premise of the application is simple. A database filled with files names and a "converted" field that has a 1 or a 2 in it (1 for unconverted, 2 for converted). The application loops through every record where "converted" = 1, retrieve the file and convert it.
My single threaded application works fine, except its far too slow. Due to the huge amount of rows in the database (4 million+) and the time constraints on the project, I have decided to run as many threads as the hardware can allow to cut down on the timings.So, the dilemma is accessing database records and which threads should grab which record and how.
View 3 Replies
Nov 23, 2011
I have a function in my program that adjust sales for multiple days. Sometimes it needs to adjust up to 3 months and the tasks takes a while so I decided to split up the work between multiple threads. The way I have it working is say I need to adjust 3 months. I have the first thread adjust sales for the 1st month, the second thread adjust sales for the 2nd month and finally a third thread that will adjust sales for the 3rd month. Since all three threads are performing the same tasks except for different date range they use the same procedures. Within those procedures I make a call to the database to extract the sales for the given month. At some point it seems like the threads start to use the same SQL Data Objects because I am receiving the below error."There is already an open DataReader associated with this Command which must be closed first."Below is the first procedure that is ran by each thread up to the line where it errors out.
Private Sub Process_Adjustments(ByRef objAdjustBillCodeThreadParameters As clsAdjustBillCodeThreadParameters)
Dim cmd As SqlClient.SqlCommand
[code]....
So all three threads call this subroutine and the first thread does the data fill with no issues and then sometimes even the second thread does the data fill with no issue but then the third thread crashes and produces the above error. It seems as though the threads are sharing the same SQL Objects when all objects are local to the sub and I always thought each thread had it's own memory to work with. So I thought each thread would call the sub create it's own objects in memory, but that does not seem like what it's doing. I have other multithreading processes in my application that work perfectly fine, this is the first time I am attempting to multithread in this manner where I am using the same procedure within multiple threads.
Just thought of something that I might be doing wrong. The subroutine in question is in the same class where the threads are created. Should the subroutine be in it's own class, and therefore each instantiation of that class?
View 3 Replies
Nov 13, 2009
I try to use Multithreading with VB 2005. I added a Listbox to main form and i tried to fill ListBox with 2 threads. When i executed code it told me that this is unsafety operation becasuse of ListBox is created with Main(Form1) form.
Is there anybody who has such simple multithreading example with Mutex or such lock mechanism?
View 1 Replies
Jun 8, 2010
what is the right way of Multithreading in visual studio 2008.
View 1 Replies
Aug 10, 2010
I m making a project in which it check website about there status (Online / Offline) through there status code and when project is in processing it hang's until the whole line of code complete
[Code]...
View 5 Replies