system timer help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

im new to this so please forgive my ignorance.
Im using vb dot net with compactframework and basically want to
kick method x(arData() as string,p_cFile as string) off on a timer
However i dont want the the timer to kick off again till x is definatley
finished ?

Im sure its simple any code would be helpful

TIA

Stu
 
Use a forms.timer or a threading.timer and in their callbacks/eventhandler
call your method.

Forms.timer: on first line of the tick eventhandler method set enabled=false

Threading.timer: pass -1 as the argument after the interval.

MSDN describes both classes pretty well so check it out (google is also
good).

If you are having problems, post back with the code you tried...

Cheers
Daniel
 
Hi Daniel,

So far ive tried this its on a non visual form

Dim objSettings As New clsSettings
Dim arDataUrls() As String
Dim objTimerState As Object
Dim objProcess As New clsProcess

Dim autoEvent As New AutoResetEvent(True)
Dim delayTime As New TimeSpan(0, 0, 0)
Dim intervalTime As New TimeSpan(0, 0, 0, _gnPollInterval)
Dim objTimer As Timer

Dim timerDelegate As TimerCallback = _
AddressOf objProcess.processData

Try

arDataUrls = objSettings.loadSettings()

If IsNothing(arDataUrls) Then
Throw New Exception("Unable to load setting information")
Else
With objProcess
.urlDataArray = arDataUrls
.overLayFileName = _gcOverlayFile
End With

objTimer = New Timer(timerDelegate, autoEvent, delayTime,
intervalTime)
'objProcess.processData(objTimerState)
End If
Catch ex As Exception

End Try

However in my processData code i am doing a webrequest repeatedly
to get data from different url pages

objRequest = System.Net.WebRequest.Create(p_cUrl)
which works fine until you call it in the timer and then it says
NOTSUPPORTEDEXCEPTION

Any ideas please
 
Hi Daniel,

Should the change be in the process data method itself in which case how do
i pass the timer object to it ?

Or in the main method

objTimer = New Timer(timerDelegate, objAutoEvent, delayTime, -1)
' Wait for delegate to finish

objAutoEvent.WaitOne()
objTimer.Change(0, _gnPollInterval)

Which seems to cause an exception

Thanks

Stu
 
Back
Top