473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Start as Minimized Memory Usage

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
Jan 11 '07 #1
6 1900
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
Jan 11 '07 #2
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.
"Allen" <Al***@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
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


Jan 11 '07 #3
Allen

Take a look at the 'Application Main' class in the Windows Forms folder of
the September 2005 MSDN Magazine. Its the 'Weather Alerts' example

Has a nice, simple Toast Window too

Here's the direct download:

http://download.microsoft.com/downlo...ndowsForms.exe

I hope this will help

Newbie Coder
Jan 11 '07 #4
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]

"Stephany Young" wrote:
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.
"Allen" <Al***@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
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


Jan 11 '07 #5
A solution that works very well is:
http://www.coversant.net/dotnetnuke/...d=88&EntryID=4

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, MVP C#
http://www.coversant.net/blogs/cmullins

"Allen" <Al***@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
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


Jan 11 '07 #6
Haven't tried it yet, but looks very nice and clean. Thanks much for code.

"Chris Mullins [MVP]" wrote:
A solution that works very well is:
http://www.coversant.net/dotnetnuke/...d=88&EntryID=4

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, MVP C#
http://www.coversant.net/blogs/cmullins

"Allen" <Al***@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
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


Jan 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Peretz | last post by:
I am trying to optimize my C# program, but no matter what I try the application keeps eating memory. I verified all the references and even got special software to count references. I made sure all...
5
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory...
40
by: Brian Jorgenson | last post by:
On my web page, I have a few hyperlinks with target frame of _blank. The hyperlink brings up a second window, but everytime I click on thie hperlink, it keeps bringing up a new window and not...
2
by: Jarvis | last post by:
I've made a testing program to test the memory usage of some Data Forms. I create a MDI parent form with one single MDI child form, which is a Data Form generated by .NET Data Form Wizard. To...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
6
by: Ganesan selvaraj | last post by:
I using C# .net. i want to split the text files based of the some condition. my source text file size may be 4 kb to 4 gb. some time when i split the i got the "out of memory exception. when i...
20
by: Philip Carnstam | last post by:
How come .Net applications use so much memory? Every application I compile uses at least 10 MB of memory, even the ones consisting of only a form and nothing else. If I minimize them though the...
19
by: Oliver Neumann | last post by:
Hello, im new to c# and i got an app with a notifyicon. Now i want to start the app only with the notifyIcon, so that the Main-Form doesnt show up. The form itself is used at the entrance...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.