Start as Minimized Memory Usage

G

Guest

When minimizing Visual Basic application, working memory is greatly reduced
from about 20 MB to only about 2 MB. However I want the application to
start as minimized, and most of the time it will remain minimized, never
being brought to normal or maximized view and consequently then minimized.

However when started minimized the working memory stays at 20 MB until the
app is restored to normal/maximized and then minimized.

How do I get the working memory down to 2 MB programmatically when starting
the app minimized?

TIA
 
N

Newbie Coder

Allen

Over a year ago there was a nice piece of code in the MSDN magazine that
starts an application in the System Tray withought actually drawing the form
until the icon was double-clicked. Spent about 30 mins looking for this code
but I don't remember which month it was in.

Most people will assign a TrayNotifyIcon control to a form & then run the
app from Sub Main, adding the icon to the tray, but an invisible instance of
the form is still there, which can be proved but enumerating the Desktop
windows using a callback function, yet the MSDN Magazine code article
removed that form, which would be absolutely perfect for your needs. I only
wished I could find that code for you.

This is the URL for the MSDN Magazine code:

http://msdn.microsoft.com/msdnmag/code.aspx

Sorry, I cannot be of more help,

Newbie Coder
 
S

Stephany Young

What you are talking about is the 'WorkingSet'. If you continue to refer to
is as 'working memory' then you all you are going to do is confuse everyone
including youself.

Have a look at the documentation on the System.Environment.WorkingSet64
property for some more information.

By 'when started minimized', I assume that you are refering to setting the
WindowState property of your startup form at design time.

Instaed of setting it at design time you could try setting it in your
Form.Load event handler.
 
G

Guest

Hello

as long as the application domain is loaded the memory will be reserved
for further processing

if your comp would run low on resources and the app does not need the memory
at the moment ( cause it is idle ,,, the memory would be given back and
needs to be reclaimed )

with a windows form application you can see this behavior to ( or did you
really thought a clean form needs about +- 25 megs in .Net ? )

there is a way you can bypass this behavior however it comes with a small
price ,,,,
i wrote once a remoting project , and had my customer complaining about the
memory consumption , so i digged a litle bit deeper and came with this
solution

my project ( wich is a singleton ) starts a timer that periodicly checks a
datetime var to see how manny time has passed after it was last called
if this intervall is >= 1 minute it will call SetProcessWorkingSetSize()
wich will trim the data usage to a minimum see below code ( sorry VB.Net
-) )


Private M_dtLastUsage As DateTime

Private oCallback As New TimerCallback(AddressOf OnTick)

Private oTimer As Threading.Timer

Public Sub OnTick(ByVal stateInfo As Object)

Dim DtCurrent As DateTime = Date.Now

Dim elapsed_time As TimeSpan

elapsed_time = DtCurrent.Subtract(M_dtLastUsage)

If elapsed_time.TotalMinutes >= 1 Then

oTimer.Dispose() : oTimer = Nothing

SetProcessWorkingSetSize()

End If

End Sub

Public Sub New()

M_dtLastUsage = Date.Now

If IsNothing(oTimer) Then

oTimer = New System.Threading.Timer(oCallback, Nothing,
System.TimeSpan.FromMinutes(0), System.TimeSpan.FromMinutes(1))

End If

End Sub



Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll"
(ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As
Boolean

Friend Sub SetProcessWorkingSetSize()

Try

Dim Mem As Process = Process.GetCurrentProcess()

SetProcessWorkingSetSize(Mem.Handle, -1, -1)

Catch ex As Exception

End Try

End Sub

The drawback of this method is that the framework needs to reclaim the
memory again so in theory your prog should be a few miliseconds slower as it
could be.

So it is more cosmetical as that it does really have a purpose as the prog
is actually gone to the swap same as a minimized application ( physical and
virtual memory thingy )


Regards
Michel Posseth [MCP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top