Solved

vb.net threadcounter

Posted on 2012-03-22
6
180 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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