Results 1 to 8 of 8

Thread: [RESOLVED] Runtime error on a CPU% project

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Resolved [RESOLVED] Runtime error on a CPU% project

    Hello y'all o/
    It's me again.

    The following code will show CPU and RAM usage percentage on a pair of label and progress bars.
    Code:
    Public Class Form1
        Private CPU_Using As New PerformanceCounter()
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Private Function CpuId() As String
            Dim computer As String = "."
            Dim wmi As Object = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & computer & "\root\cimv2")
            Dim processors As Object = wmi.ExecQuery("Select * from " & "Win32_Processor")
    
            Dim cpu_ids As String = ""
            For Each cpu As Object In processors
                cpu_ids = cpu_ids & ", " & cpu.ProcessorId
            Next cpu
            If cpu_ids.Length > 0 Then cpu_ids = cpu_ids.Substring(2)
    
            Return cpu_ids
        End Function
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            CPU_Using.CategoryName = "Processor"
            CPU_Using.CounterName = "% Processor Time"
            CPU_Using.InstanceName = "_Total"
            Dim Rounded_CPU_Usage As Double
            Rounded_CPU_Usage = Math.Round(CPU_Using.NextValue())
            CPUvalue.Text = Rounded_CPU_Usage & "%"
            CPUmeter.Value = CInt(Fix(Rounded_CPU_Usage))
            RAMmeter.Value = Math.Round((Val((My.Computer.Info.TotalPhysicalMemory) - Val(My.Computer.Info.AvailablePhysicalMemory)) / Val(My.Computer.Info.TotalPhysicalMemory)) * 100)
            RAMvalue.Text = RAMmeter.Value & "%"
        End Sub
    End Class
    The code is quite fine and tested. The problem is when I open the solution project file (Which was created on a win10 console) on a win7 similar x64 architecture with a totally same Microsoft Visual Studio 2012 edition software, it start not to syntax error the line:
    Code:
    Rounded_CPU_Usage = Math.Round(CPU_Using.NextValue())
    But when I run the app, major fault which led to debugging the app appears. (I am away from the mentioned workstation. I will add a photo of the error details ASAP as an edit soon)
    It should be noted that commenting that single particular line will rectify the matter.

    I insist, no more related codes and libraries like ones below was imported.
    Code:
    Imports System.Runtime.InteropServices
    Imports System.ComponentModel

  2. #2
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Location
    USA
    Posts
    393

    Re: Runtime error on a CPU% project

    Do you have the same framework installed on the windows 7 as the one that you are using to program with on windows 10?
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

    Useful Things:

    How to link your VB.Net application to Excel

  3. #3

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Re: Runtime error on a CPU% project

    Here's the error details.
    Attachment 181403

    Quote Originally Posted by Frabulator View Post
    Do you have the same framework installed on the windows 7 as the one that you are using to program with on windows 10?
    I'm not sure. How can I find it out?
    ------------------------------------------------------------------------------------------------------------------------
    Anyways, I tried to install .NET framework 4.8 caused VS2012 to crash and not-responding @ startup. Is it still possible to be a part of .net?
    Last edited by pourkascheff; May 11th, 2021 at 02:44 AM.

  4. #4
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Location
    USA
    Posts
    393

    Re: Runtime error on a CPU% project

    you can check your .net framework by going into your VS project settings and looking at the General> Target Framework.

    Just from memory, I think 4.3 was the default in 2012.

    Anyway, make sure that you have the correct framework (or lower) installed on the target machine as the target framework. For me, I always go with 4.0, as framework 4.0 is compatible with XP and up.

    That would be the first thing I check for compatibility.
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

    Useful Things:

    How to link your VB.Net application to Excel

  5. #5

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Re: Runtime error on a CPU% project

    Problem solved by:
    * Renewing windows.
    * Reinstalling same version but from another provider maybe with some built-in stuffs.

    Just for a record/.
    Pourkascheff signing out

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: [RESOLVED] Runtime error on a CPU% project

    Not every version of VS works with every version of the framework. For example, VS2010 will work with framework versions up to 4.0. I would be surprised if VS2012, which was the very next version after VS2010, would work with FW4.8. It should run fine with that being on the computer, but it won't let you target that. Not every framework will work on every version of Windows, either. I didn't think that FW 4.8 would work with Windows 7, for example, so I'm a bit surprised that you were even able to install it. On the other hand, maybe it didn't work.

    Personally, I have long felt, and still feel, that VS2012 was probably the worst version of VS ever released. It was ugly compared to the ones before or after, and added pretty much nothing. There are arguments against VS2015, as well, but VS2012 was still worse. One could also argue that VS2002 or VS2003 was worse, but they were not bad at the time they were released, they are just bad in comparison to later versions. The same could be said of VS2005, which was really quite nice for it's time. Thus I would say that VS2012 was the worst of them all. So, if you can move on, then move to VS2017 or VS2019. Otherwise, go back to VS2010, which may have been the most beautiful version.
    My usual boring signature: Nothing

  7. #7
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Location
    USA
    Posts
    393

    Re: [RESOLVED] Runtime error on a CPU% project

    Quote Originally Posted by Shaggy Hiker View Post
    So, if you can move on, then move to VS2017 or VS2019. Otherwise, go back to VS2010, which may have been the most beautiful version.
    I agree. I used 2010 for a very long time, and recently upgraded to 2019. Both are solid.
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

    Useful Things:

    How to link your VB.Net application to Excel

  8. #8
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: [RESOLVED] Runtime error on a CPU% project

    Quote Originally Posted by Shaggy Hiker View Post
    Not every version of VS works with every version of the framework.
    Sounds just like... DLL Hell!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width