Results 1 to 9 of 9

Thread: Loss of memory.

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,492

    Loss of memory.

    Hi,
    I'm trying to set-up a much used application from a previous computer (Win.10) in a new computer (Win.11), one subroutine starts:
    Code:
    Private Sub PMC(ByVal sender As Object, ByVal e As PowerModeChangedEventArgs)
            If e.Mode = PowerModes.Resume Then
    But I've forgotten what I need for it to work, I seem to remember that I needed to add a DLL somewhere, but there are dozens of them in the previous laptop so I can't tell which one to use or where to put it.

    Poppa
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,846

    Re: Loss of memory.

    This

    https://learn.microsoft.com/en-us/do...owsdesktop-9.0

    seems to indicate Microsoft.Win32 is needed.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,947

    Re: Loss of memory.

    Code:
    Imports Microsoft.Win32
    There are mentions online of combining PowerManagement in your app. with a windows service that runs all the time your computer runs. But I don’t know how you originally wrote your application…

  4. #4

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,492

    Re: Loss of memory.

    Quote Originally Posted by .paul. View Post
    Code:
    Imports Microsoft.Win32
    There are mentions online of combining PowerManagement in your app. with a windows service that runs all the time your computer runs. But I don’t know how you originally wrote your application…
    Thanks .Paul, That code is already there, right above 'Public Class Form1'.
    Ought I to add Win32 somewhere? It's in dozens of places already, mostly with something added after the 'Win32' bit.
    Along with the sunshine there has to be a little rain sometime.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,984

    Re: Loss of memory.

    You need to read the documentation. The documentation for EVERY type tells you what namespace it's a member of and what assembly it's defined in. Note that the assembly may vary by .NET version. You're using the PowerModeChangedEventArgs and PowerModes types, so read the documentation for those types. In .NET 9, they are defined in Microsoft.Win32.SystemEvents.dll. In .NET Framework 4.8.1, they are defined in System.dll.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,492

    Re: Loss of memory.

    Quote Originally Posted by jmcilhinney View Post
    You need to read the documentation. The documentation for EVERY type tells you what namespace it's a member of and what assembly it's defined in. Note that the assembly may vary by .NET version. You're using the PowerModeChangedEventArgs and PowerModes types, so read the documentation for those types. In .NET 9, they are defined in Microsoft.Win32.SystemEvents.dll. In .NET Framework 4.8.1, they are defined in System.dll.
    I've really tried to understand what Microsoft is telling me but I'm baffled. Where they do give examples they're in C++ which may as well be in Latin. I can't find anything of use, you'll've seen elsewhere in this forum that I've tried to test what code I do have, (which works perfectly well in the application that I use in a Win.10 machine) but which fails to even call the method in this Win.11 one.
    I'm no further with a solution to my problem.

    Poppa
    Along with the sunshine there has to be a little rain sometime.

  7. #7
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,834

    Re: Loss of memory.

    Quote Originally Posted by Poppa Mintin View Post
    I've really tried to understand what Microsoft is telling me but I'm baffled. Where they do give examples they're in C++ which may as well be in Latin. I can't find anything of use, you'll've seen elsewhere in this forum that I've tried to test what code I do have, (which works perfectly well in the application that I use in a Win.10 machine) but which fails to even call the method in this Win.11 one.
    I'm no further with a solution to my problem.

    Poppa
    The online documentation for .Net generally defaults to C# (not C++ although that is available), you can choose the language you want the sample code to be displayed in near the top of the page - look for where it says C# or C++ and click the dropdown to display it in your preferred language.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,984

    Re: Loss of memory.

    Quote Originally Posted by Poppa Mintin View Post
    I've really tried to understand what Microsoft is telling me but I'm baffled. Where they do give examples they're in C++ which may as well be in Latin. I can't find anything of use, you'll've seen elsewhere in this forum that I've tried to test what code I do have, (which works perfectly well in the application that I use in a Win.10 machine) but which fails to even call the method in this Win.11 one.
    I'm no further with a solution to my problem.

    Poppa
    None of that's really relevant to the issue I addressed. You were saying that you didn't know what library to use to make that code work and I told you how to find out. The answer to that has been the same for almost 25 years. That doesn't mean that there aren't other issues but now you know how to find out what assembly a type is defined in, you won't have to ask again. As for where to put it, there is no putting it anywhere for a first-party assembly. If it's .NET Framework then you reference it and if it's .NET Core then you install the NuGet package. Again, nothing new.

    As for language, the vast majority of examples are provided in both C# and VB. That you don't know that you can select the language from the drop-down at the top of the page just means that you haven't spent the time you should have to explore the documentation. As mentioned, it will default to C# but there's a drop-down arrow right next to the language at the top of the page. All you had to do was change that to VB once and it would then default to VB for you every time in the future. Imagine how many questions you could have answered for yourself if you'd learned how to use the documentation years ago. When I first started answering questions on this forum, I had no idea about many of them so I just read the documentation that the person asking the question hadn't bothered to and provided the answer that they could have found for themselves. The documentation won't answer every question but it will answer many and should always be consulted before asking elsewhere.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    New Member
    Join Date
    Mar 2025
    Posts
    5

    Re: Loss of memory.

    Quote Originally Posted by Poppa Mintin View Post
    µµBut I've forgotten what I need for it to work
    I literally pasted your post into ChatGPT and it said you need this:

    Code:
    AddHandler SystemEvents.PowerModeChanged, AddressOf PMC

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