Solved

vb.net threadcounter

Posted on 2012-03-22
6
178 Views
Last Modified: 2012-04-01
Hi Experts,

I am looking for at counding the number of active threads at any one time.

The best I can do is

Imports System.Diagnostics
Imports System.Threading


Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        Label1.Text = "Processes Name"

        Label2.Text = "Total = "

        Button1.Text = "Get Current Processes"





    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim count As Integer = 0

        label2.Text = "Total = "

        Dim prs As Process() = Process.GetProcesses()

        ListBox1.Items.Clear()

        For Each proces As Process In prs


            count += 1


            ListBox1.Items.Add(proces.ProcessName)
        Next

        Label2.Text += count.ToString()

        Dim proc As Process = Process.GetCurrentProcess()
        MsgBox("Number of Threads active: " & proc.Threads.Count.ToString(), MsgBoxStyle.Information, "Threads Active")

    End Sub




End Class


The problem is I originally tapped this up in VS2010, and throught bonza, its working... on an Windows Server 2003 box in a development environment it again showed consisten results, however it didnt run on the production box because of not having .NET 4 installed so dropped it down to .Net 3.5 via VS 2008 and then the thread count is out by 7 on the dev box, but spot on on my machine where it was originally built.

Any ideas welcome...

Thanks

Simon
0
Comment
Question by:SimonPrice33
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37765208
Are you comparing the count with Task Manager count?
0
 

Author Comment

by:SimonPrice33
ID: 37765213
not yet..

what i actually want to do is count for a specific application but at the moment I just need some consisten results..

the task manager is reading over 1400, the one above is reading between 12 - 15 via .Net 4 and 5 on .Net 3.5.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37767099
>then the thread count is out by 7 on the dev box
>not yet..


Then how do you know its out?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:SimonPrice33
ID: 37770179
i know its out becsause both the .net 3.5 and .net 4 versions of the app were both run on the dev box at the same time.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37772324
If you step through the code and

 Process.GetProcesses()

is return a different number of items in both apps then I think you would need to abandon the process class and use win32 API calls to get process and thread information.
0
 

Author Closing Comment

by:SimonPrice33
ID: 37793360
.
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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 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

20 Experts available now in Live!

Get 1:1 Help Now