You can use P / Invoke for the Win32 CreateMemoryResourceNotification API with the LowMemoryResourceNotification parameter. This returns a notification object that you can either poll (using QueryMemoryResourceNotification) or wait (in the background thread, you will need to use one of the Win32 wait methods and not the .NET wait method, or perhaps get a custom class from WaitHandle to encapsulate the object Win32). You will respond by dropping blocks from your cache and forcing garbage collection; youโll need to check if itโs enough that the user never feels that the system is slowing down. "
In addition, looking at the documents, the threshold for receiving notifications with low memory is really low memory (32 MB on a 4 GB system!). I suspect that by that time the user may already feel a slowdown, and swapping your application in memory to reset its blocks may cause noticeable disk access. Again, you can appreciate this when testing.
source share