|
Yup, your right, the static approach is misleading. You can fix it by calling p.Refresh(). The memory isn't exactly static in my simple example, but it stabilizes after a few minutes. I saw the same basic pattern with the using statement.
None the less, the bytes/second allocated seems quite high. I ran the allocaiton profiler on it, and found that the bulk of memory dynamically allocated for my simple test was in System.Diagnostics.ThreadInfo. Again, it looks like the System.Diagnostics.Process class is rather heavyweight for your purpose. I guess it's snapshotting a whole bunch of information you don't need...
You can get working set size from the Environment object, it's lots cheaper, but even with this, I do see an ongoing increase in private bytes by just reading Envrionment.WorkingSet. Interesting... Allocation Profiler says its related to security checks code, that's more what I expect. I leave it running for quite some time and eventually the GC kicks in and trims working set back. I haven't left this running overnight, but I will...
Burt Harris
|
|
|
|
|
I added in the .Refresh() and the memory usage started changing like it used to. Seeing this, I left it running for a few hours and after 7+ hours, the memory usage has a peak of 110 meg (set 5 mins ago), a current memory of 60 meg, and it never dropped below its initial value of 20 meg since the app started.
The main memory usage seems to occur when reading the event log, as when it is checking cpu usage the memory changes a small amount (~100k) but seems stable. It seems to be having problems when reading the event log into a datatable and then displaying that in a datagrid.
It also seems, since I made the Process object static, that a) initial memory usage has jumped (from 10 meg to 20 meg), and that peak memory usage has doubled as well (previously it peaked around 40 - 50 meg, now it's 110 meg).
I am not talking about a lot of data being stored in memory consistently - the datatable has a max of 10 records, and I clear the datatable at the beggining of each loop through the current log (cycling through system, security, application logs every 10 secs for testing purposes).
Is it the Process that is using up so much memory? - I call the p.WorkingSet every 2 secs currently, but now I am only calling the
Refresh(), not creating a new instance of the object. Is there a more "light weight" way of checking the memory usage of a the current app? Maybe calling the Process object is itself causing the high memory usage?
|
|
|
|
|
Welcome to CP Burt! It's always nice to have more people from Microsoft here to answer questions.
So you work in the Speech group huh? Gotta say, I love the .NET Speech SDK. Very nice...even more so that it works with ASP.NET. I send my kudos along to your team.
How did you find out about CP? Was it purely accidental, a coworker mentioning it to you, or was there an internal memo that everybody should monitor what Nick says in his column?
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
Thank you David. Glad you like the .NET Speech SDK. I can't take much credit for it, I've been working on a related project that hasn't shipped yet, but if you like the SDK, we're probably on the right track.
I found CodeProject tracking down rumors that turned out to be Pavel Zolnikov's Command Prompt Explorer Bar. Now that's some cool software. I'm still studying it, but already I'm impressed.
So there wasn't any sort of all-hands memo, but I will say that there is awareness inside Microsoft as to how important it is we contribute to the developer community. I heard a VP up my reporting chain say he tries to start and end each day solving a customer problem, on message boards or elsewhere. I don't know what forums he haunts, but that's pretty cool.
Topics like this seem like a good place for me. I've got solid server-grade code written in C#, and handling audio data with near real-time requirements. There are a lot of people, (even within Microsoft), who are skeptical of managed code, but my team has taken the plunge, and making it work for our somewhat challenging performance goals hasn't been that hard.
Turning back to the original topic of this thread, what I've learned is that managed memory doesn't mean you won't have memory problems: there are new kinds of memory problems. Understanding the memory allocation behavior your apps is key. With a tools like the allocation profiler, and a little patience, I think most developers will find that solving the new style memory problems (generally performance) a lot easier to diagnose and address than old-style ones (like dangling pointers).
Even with tuning, managed apps will generally use more memory than unmanaged ones, but very high memory consumption indicates a bug in either.
Burt Harris
|
|
|
|
|
Burt Harris (msft) wrote:
I found CodeProject tracking down rumors that turned out to be Pavel Zolnikov's Command Prompt Explorer Bar. Now that's some cool software. I'm still studying it, but already I'm impressed.
I think everybody loves that thing! I use it all the time. It's worth the extra few seconds it takes to start up cmd.exe and put it in the window.
Burt Harris (msft) wrote:
So there wasn't any sort of all-hands memo, but I will say that there is awareness inside Microsoft as to how important it is we contribute to the developer community. I heard a VP up my reporting chain say he tries to start and end each day solving a customer problem, on message boards or elsewhere. I don't know what forums he haunts, but that's pretty cool.
That's really cool. I'm glad to know that most of you guys really are concerned with our comments. I for one, laugh at people who say that Microsoft is a huge corporate giant that doesn't care. And I can do that because of people like you, your VP, Eric Gunnerson, and Nick Hodapp. I must say kudos to you guys. It's a lot easier to solve a problem when someone with the inside scoop comes along to help you out.
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
My quest for .NET equivalents doesn't seem to end.
How do I "EndDialog" a Form? Close() works, but I can't pass a result for ShowDialog.
I already found the Button.DialogResult member, but I want to do some extra processing before closing the dialog.
If I could find a souvenir / just to prove the world was here [sighist]
|
|
|
|
|
Funny, I thought I replied to this already.
You can override the value assigned to the DialogResult property when the user clicks the Close button by setting the DialogResult property in an event handler for the Closing event of the form.
Burt Harris
|
|
|
|
|
Burt Harris (msft) wrote:
Funny, I thought I replied to this already.
yep, got three notifs
thanks!
If I could find a souvenir / just to prove the world was here [sighist]
|
|
|
|
|
Q1-if a system is in loggoff state and i call
GetUserName(..).
is the function fails,and return value is zero?
and how did i know that the system is in loggoff state?
//////////////////////////////////////////////////////////
Q2-how i will trap the WlxDialogbox and where msgina asks for the userid,password
and fill in the fields by my self?
can any body help me in this regard?
//////////////////////////////////////////////////////////
Q3-how did i find the system32 path programatically?
//////////////////////////////////////////////////////////
Q4-if i call BlockInput(true)
and then i want to use postmessage or sendmessages for keyboard and mouse
will these messages works?
/////////////////////////////////////////////////////
r00d0034@yahoo.com
|
|
|
|
|
Sounds like your trying to replace the login dialog. This is intentionally difficult (near impossible) to do. NT/W2K/XP guarentees that when you type Ctrl+Alt+Delete, the dialog is the trusted login dialog, and not something that might steal your password.
If you want auto-login, there is a registry setting that lets you specify a username and password. I'd only reccomend using this if the machine is in a physcially secure location.
Burt Harris
|
|
|
|
|
I am trying to do some Custom Drawing within the TextBox in .NET. I have finally figured out how to do it and the gradient Background / ForeColors look great! However, there is a big drawback. It seems that when the TextBox receives focus, for some reason it makes the Text twice the size (from 8pt to 16pt)!
Would anyone know why this is happening? I can't really post the Source Code because there is a lot! I am Deriving from the TextBox and Setting the Styles on it to:
SetStyle(ControlStyles.UserPaint, True)
SetStyle(ControlStyles.ResizeRedraw, True)
SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
The TextBox then handles mainly the OnPaint & OnPaintBackground. I've also had to handle the OnLostFocus / OnGotFocus to do painting to override the Base painting since Painting events do not fire unless all the Text is Selected.
|
|
|
|
|
Perhaps you are manipulating the hDC scaling parameters and not restoring them before calling the base class.
Burt Harris
|
|
|
|
|
I'll look into it, but I don't think so since I don't even know how to do that .
|
|
|
|
|
I want to see if I am connected to internet and have the ability to show connections dialog box,I know how to do it with Rasapi32.lib library,I want to know if .NET provide some classes for it or not.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I believe so, within the System.Net Classes. I can't remeber but there is some code out there somewhere on doing Connections with .NET. Check www.planetsourcecode.com.
|
|
|
|
|
I started working on a RAS wrapper for .NET , but I have no RAS connection anymore so development stopped. I can mail you what I have, to be honest I cant remember how far I got in respect to UI bit, but it has the abilty to connect/disconnect, enum dialups/connections. [edit] seems UI support is there [/edit]
Let me know
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET
|
|
|
|
|
Thank you leppie,I just want to learn how to dialup with C# (with .NET framework).I know how to do it with RAS library in C#,I want to know if .NET has any support for itself,not with old library .
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Mazdak wrote:
I just want to learn how to dialup with C# (with .NET framework).I know how to do it with RAS library in C#,I want to know if .NET has any support for itself,not with old library .
No support, but what you will see in the future perhaps is wrappers like the Office assembles which makes use from .NET easier.
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET
|
|
|
|
|
i want to start a process.for that purpose i am using
this code?
string strProcName"c:\\yplayerinstall.exe";
Process tmpProcess;
tmpProcess = new Process();
tmpProcess.EnableRaisingEvents=true;
tmpProcess.StartInfo.FileName=strProcName;
try
{
tmpProcess.Start();
while(! tmpProcess.Responding) System.Windows.Forms.Application.DoEvents();
}
catch
{}
the above code run sucessfully but when i want to start that exe on the network it does not run.
for example the path is this
-------------------------------------------
\\Imran1\SOFTWARE\Yahoo Player\yplayerinstall.exe
--------------------------------------------
where imran1 is computer name and rest of them are folder names.
if i type this address on start->run then the process executed.
Prcess.start does not work i dont know why?
although i have full rights and i can start that exe by double clicking it?
r00d0034@yahoo.com
|
|
|
|
|
Is this a Windows Installer package you are trying to run or a standard EXE? I have noticed that when I try to run Install Packages based on Windows Installer, they will not run unless I Map a drive to the Network directory I am installing from. Have no idea why...
|
|
|
|
|
I think this is by design. The .NET Framework implements a code access security model, that limits access not only based on who is running the code, but where the code came from. The idea is to prevent malicious code from doing damage to your system.
Code installed on your local machine is granted full permissions by default, but code downloaded from another machine is limited based on concepts similar to the Internet Explorer security zones, local intranet, internet, trusted sites, restricted sites. Its possible to change the policies that determine what code can do what, but in your case that's probably not the right thing to do.
It sounds like you're trying to write an installer program. Packaging your application as a Windows Installer package (.MSI file) is a better approach. In installing your package, the user makes a decision to trust your code, then it runs from the local machine, with full permissions. If you need to perform special steps during setup you use a "custom action", which are supported in .NET using the System.Configuration.Install.Installer class hierarchy.
It's not a simple change, but learning about it is probably worth while. Try adding a Visual Studio "deployment project" to your solution. Select the deployment project in the solution explorer and be sure to click on the icons that appear at the top of the solution explorer, they aren't obvious at first, once you discover them your on your way.
Burt Harris
|
|
|
|
|
I am writing an application than needs to know if a given date is equal to the start of daylight saving time for the pacific time zone.
Does anybody knows how to do this? Sample code is most appreciated.
|
|
|
|
|
|
Hi,
Presently i have a client server application in C# where server will be listening to port X in an infinite loop.When a client connects to it , it serves the client.Once its doen serving the client,its goes to loop again.
What iam looking for is to have server doing some task and also listening to the port as well.once it gets connection request from the client , it stops its task,serves the client and then continues its task.
I thought of doing this with two threads where in one thread it will listening for the clients and in the other thread it will be doing some task.
In the thread where it comes to know that a client has contacted it, it should signal other thread to stop its task and resume task only when client is served.
Any help on this will be greatly appreciated.Iam doin this in C#.
Srinivas Reddy
|
|
|
|
|
So the hot way of doing this in C# is to use the asynchronous pattern. This uses multiple threads, but not so explicitly.
Think of it this way: You need one thread that uses Socket.Accept to listen for new connections on the port as you describe. However, when a connection comes in, you don't need to spawn another thread, let the runtime will manage threads for you.
You'll probably want to post a read in response to the connect. Do so with an async method, like NetworkStream.BeginWrite(). You pass a delegate to that method, and when the read completes, the runtime will call you back on what's called a "thread pool" thread. That callback will do some work, and post another asynchronous I/O operation instead of blocking. This way, the thread can return back to the thread pool and be used to service more than one client. This scales much better than a thread-per-client approach. Under the covers, the runtime uses a powerful (if obscure) feature Windows NT call "I/O completion ports", but as a C# programmer, it's fairly easy.
It does call for a design shift. You don't want to block thread-pool threads waiting for I/O, especially network I/O. Instead, you have to break your logic into a set of routines that gather the results from a previous I/O operation (like NetworkStream.EndRead()), do some work, and start another asynchronous operation, perhaps respond using NetworkStream.BeginWrite(). You can even do a BeginWrite follwed with a BeginRead and have both active at the same time, since the Begin methods don't wait for completion.
Warning: Having blocking (synchronous) network call nested deep in several subroutines breaks the model!
The ideal is that you have one thread-pool thread per CPU on your server. That way they can all be working, but you don't encounter excessive context (i.e. thread) switching overhead. In the real world, you typically need more than that because of unpredictable blocking I/O operations like page faults. The runtime & OS dynamically adjust the number of threads to match your program's behavior.
You don't even really need a thread to wait on the Socket.Accept function, as it has an async pair BeginAccept and EndAccept as well.
P.S. I/O Completion ports aren't available on Windows 9x & ME, but don't worry about that, the runtime simulates them if necessary.
Burt Harris
|
|
|
|
|