Peter_Ankarlou
asked on
Finding a system.threading.timer from its ToString and make dispose of it in VB.NET
Hi!
I am writing an application for scheduling database queries, dtsjobs and store procedures. I am launching a lot of Timer objects. I store their ToString() sentences into a string variable which I later save on my SQL Server. However I do need to be able to dispose all these System.Threading.Timer in the event of a rescheduling task being launched by a user.
In short:
How do I find a specific Timer from its ToString. Or any ideas on how to do this otherwise?
Cheers,
Peter
I am writing an application for scheduling database queries, dtsjobs and store procedures. I am launching a lot of Timer objects. I store their ToString() sentences into a string variable which I later save on my SQL Server. However I do need to be able to dispose all these System.Threading.Timer in the event of a rescheduling task being launched by a user.
In short:
How do I find a specific Timer from its ToString. Or any ideas on how to do this otherwise?
Cheers,
Peter
You need something like this....
Imports System.Threading
Private oThread As Thread '<----------- can make it global
If oThread.IsAlive = True Then
oThread.abort
Else
'Do something esle
End If
Imports System.Threading
Private oThread As Thread '<----------- can make it global
If oThread.IsAlive = True Then
oThread.abort
Else
'Do something esle
End If
ASKER
Why Bob?
That's truly a good question. :-)
planocz:
The thing is I am using System.Threading.Timer and I want to be able to kill it from another class in my app. What happens if I uses
Public Function KillEvent(ByVal strTimerName As String) As String
Dim x As Integer
Dim prc() As Process
prc = Process.GetProcesses
For x = 0 To UBound(prc)
If prc(x).ProcessName = strTimerName Then
Try
prc(x).Kill()
Return prc(x).ProcessName & " killed."
Catch
Return "Unable to terminate process"
Finally
End Try
End If
Next x
Which I have taken from this web-site. Will it kill my Timer-thread or kill the whole app? What is the difference between to kill a process and Timer.Dispose?
I cannot use Timer.Dispose since have have many timers? I want to kill em all (as Metallica would say).
That's truly a good question. :-)
planocz:
The thing is I am using System.Threading.Timer and I want to be able to kill it from another class in my app. What happens if I uses
Public Function KillEvent(ByVal strTimerName As String) As String
Dim x As Integer
Dim prc() As Process
prc = Process.GetProcesses
For x = 0 To UBound(prc)
If prc(x).ProcessName = strTimerName Then
Try
prc(x).Kill()
Return prc(x).ProcessName & " killed."
Catch
Return "Unable to terminate process"
Finally
End Try
End If
Next x
Which I have taken from this web-site. Will it kill my Timer-thread or kill the whole app? What is the difference between to kill a process and Timer.Dispose?
I cannot use Timer.Dispose since have have many timers? I want to kill em all (as Metallica would say).
just looking at it I think it will work,
but you will know through testing and debugging.
but you will know through testing and debugging.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why would you want to do this?
Bob