a problem with the intervall of System.timers.timer

Posted by Aboclodelourdes under Project Management on 2/7/2012 | Points: 10 | Views : 1766 | Status : [Member] | Replies : 3
hi i work on a project who use a windows service.
In the program, i used a timer (system.timers.timer) who have a intervall (10 mn) . But the execution's time of my function exceeds 10 mn. Also, i must have to do a pause before invoke again the function.
My service windows will turn always (24h/24).
Can you help me to resolve this problem ?
thank




Responses

Posted by: Ogipansrk on: 2/8/2012 [Member] Starter | Points: 25

Up
0
Down
Its seems to be coding issue.
paste your code...

Aboclodelourdes, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Aboclodelourdes on: 2/8/2012 [Member] Starter | Points: 25

Up
0
Down
Public Class Service1

Protected Overrides Sub OnStart(ByVal args() As String)
' Ajoutez ici le code pour démarrer votre service. Cette méthode doit
' démarrer votre service.

Try
Me.MonJournal = New EventLog
Me.MonJournal.Source = "MonService"
Me.MonJournal.WriteEntry("Demarrage du service à " & Now, EventLogEntryType.Information)

Timer1.Stop()
Timer1.Enabled = False
Timer2.Enabled = False

EcrireFichier()

Timer1.Enabled = True
Catch ex As Exception

End Try
End Sub

Protected Overrides Sub OnStop()
' Ajoutez ici le code pour effectuer les destructions nécessaires à l'arrêt de votre service.
Timer1.Enabled = False
End Sub

Private Sub Timer1_Elapsed(sender As System.Object, e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Try
Me.MonJournal.WriteEntry("Tick du Timer", EventLogEntryType.Information)
'Dim thr As Thread = New Thread(AddressOf EcrireFichier)
EcrireFichier()
'Di()
Timer2.Enabled = False
Catch ex As Exception
Me.MonJournal.WriteEntry("Erreur dans l'execution du service" & ex.Message, EventLogEntryType.Information)
End Try
End Sub

Private Sub Timer2_Elapsed(sender As System.Object, e As System.Timers.ElapsedEventArgs) Handles Timer2.Elapsed
Try
Dim eta As StreamWriter = New StreamWriter("E:\etat.txt", True)
If (Timer1.Enabled = True) Then
eta.WriteLine("Arret: Timer2 est en cours et Arret Timer1 " & " " & Date.Now.ToString())
Me.MonJournal.WriteEntry("Depassement du temps de traitement", EventLogEntryType.Information)
Me.ArreterService()
'System.Threading.Thread.Sleep(10000)
Else
Timer1.Enabled = True
Timer2.Enabled = False
eta.WriteLine("Réactivation : Timer1 est en cours et Arret Timer2 " & " " & Date.Now.ToString())
End If
eta.Close()

Catch ex As Exception
Me.MonJournal.WriteEntry("Erreur dans l'execution du service" & ex.Message, EventLogEntryType.Information)
End Try
End Sub

Private Sub EcrireFichier()
Try
Timer2.Enabled = True
Dim str As StreamWriter = New StreamWriter("E:\fichier.txt", True)
For i As Long = 1 To 100
str.WriteLine(i & " " & Date.Now.ToString())
System.Threading.Thread.Sleep(1000)
Next
str.Close()
Catch ex As Exception
Me.MonJournal.WriteEntry("Erreur dans l'execution du service" & ex.Message, EventLogEntryType.Information)
End Try
End Sub

End Class

Aboclodelourdes, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ogipansrk on: 2/8/2012 [Member] Starter | Points: 25

Up
0
Down
You are making things complicated!
In timer1_Start event ....
Timer1.stop()// no need to use this statement.
Because you are using timer1.enabled= false and timer2.enabled=false.
secondly , you are invoking EcrireFichier() method which is having sleep method and same time timer2.sleep is also having sleep method....
....you are mixing everthing....

try to analyze what you need , problem will be solved.




Aboclodelourdes, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response