Solved

vb.net threadcounter

Posted on 2012-03-22
6
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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