[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

vb.net threadcounter

Posted on 2012-03-22
6
Medium Priority
?
186 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
Industry Leaders: 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!

 

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 1500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month18 days, 19 hours left to enroll

834 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