Solved

vb.net threadcounter

Posted on 2012-03-22
6
177 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
Comment Utility
Are you comparing the count with Task Manager count?
0
 

Author Comment

by:SimonPrice33
Comment Utility
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
Comment Utility
>then the thread count is out by 7 on the dev box
>not yet..


Then how do you know its out?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:SimonPrice33
Comment Utility
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
Comment Utility
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
Comment Utility
.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

7 Experts available now in Live!

Get 1:1 Help Now