Solved

Finding a system.threading.timer from its ToString and make dispose of it in VB.NET

Posted on 2004-08-05
6
571 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:Peter_Ankarlou
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11726033
I think I always have to ask why, before anything else, someone chooses to do very complicated things.

Why would you want to do this?

Bob
0
 
LVL 27

Expert Comment

by:planocz
ID: 11726503
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
0
 

Author Comment

by:Peter_Ankarlou
ID: 11726981
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).
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:planocz
ID: 11730191
just looking at it I think it will work,
 but you will know through testing and debugging.
0
 
LVL 37

Assisted Solution

by:gregoryyoung
gregoryyoung earned 250 total points
ID: 11731655
that will kill a process not a thread ...

why not just hold references to your timers in a collection that you can search through for a given one ...

if you want to kill em all

foreach timer in mytimercollection
    timer.dispose()
end for
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 11734680
If you want to get a reference to a timer by name, then the collection can help you retrieve that:

Dim timerNeeded As Timer = myTimerCollection(name)

Bob
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unable  to create new object 9 41
Datagridview control last row back color red vb.net 4 38
Programmatically signing Word macros 4 61
Vb.Net Date Formatting Assistance 4 35
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now