|
Hi!
I have some questions:
1. Does anyone know how in runtime detect how many memory used by each class?
2. Does anyone know how to minimize memory usage of application (like unloading of unneeded assemblies or something else)?
3. Does anyone know any resource with "performance" + "memory usage" tests on Windows.Forms?
I have such situation:
I wrote application which make some automation tasks like send e-mail, generate Excel reports (office automation) and etc. Application is not too large but it’s usage of memory make customer dizzy. As you know customer dizzy become a developer soon. Now I have a great task to minimize memory usage of application. First of all I need to know how many each class use memory, second step rewrite code of such classes.
To my opinion 30-40 Mb memory usage (on computer with 128 Mb) for garbage collector is good enough...
Good Luck
Alex Kucherenko
|
|
|
|
|
I don't have answers for all of your questions, but here something to get you started
If you are creating COM objects then you can force their release by doing
MyObject=null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
Be carefull when looking at memory usage in the Task Manager it isn't telling you the whole truth. To determine the real memory usage of an application you could:
' Visual Basic .NET
Dim NotepadMemory as Integer
Dim component1() as Process
component1 = Process.GetProcessesByName("Notepad.exe")
NotepadMemory = component1(0).PrivateMemorySize
Console.WriteLine("Memory used: " & NotepadMemory & ".")
// C#
int memory;
Process[] notepads;
notepads = Process.GetProcessesByName("Notepad.exe");
notepadMemory = notepads[0].PrivateMemorySize;
Console.WriteLine("Memory used: {0}.", notepadMemory);
|
|
|
|
|
Hi everybody !
Here is pic ...
Please open to see it if browser is not auto open
In the present , I need your help so much. I want to design a form like this. Whatever I mask by Red point is neccessary. Please help me to do that.
Thank so much !
|
|
|
|
|
The post just below references a free .NET layout library.
Another url of interest, the genghis[^] project.
And of course, there are many C# controls related articles on CodeProject which act like unit blocks.
|
|
|
|
|
I’ve just upgraded to the new MagicLibrary version 1.7.4.0 (I used 1.7.0.0 before that) and have encountered a focus management problem in the DockingManager.
I have several forms and panels created inside the MagicLibrary docking manager and I have a rich textbox as my inside window/filler window.
If any of the forms inside the dockingmanager have shortcuts they will hi-jack focus from my rich textbox.
For instance if I have a panel with a “&Test” button created inside the DockingManager then I can no longer type “T” inside my Rich textbox when I do so the focus is transferred to the panel and the button is pressed.
This was not present in 1.7.0.0 (haven’t tested on 1.7.3.0).
Anybody have some clues as to avoiding this behavior.
Best regards Peter Hjortholm
|
|
|
|
|
Hi,
I have several controls in my form ( a tab form... that includes combos, edit boxes, grids, ...)....
Is there a way to know if any of this control has changed, just to change the flag and save changes ? ( I know that I could go control by control .... but is there a more generic way ?).
Thanks, greetings
Braulio
|
|
|
|
|
If I understand what you are doing, then just use events with event handlers.
All components have events for changes and stuff, for example the TextBox has a TextChangedEvent. In your form you can just add it to listen for this event.
Using properties panel on the form design just click the events button (little lightning bolt above the panel of properties) and get a list of events for the Textbox you have slected, look for TextChanged or TextChanging, and double click that field. It will add a new Event handler in your form code, and you can do what ever in that method. It is the exact same as a button1_Click( object sender, MouseEventArgs e ) that you most likely have probably used before. All otehr controls have events as well, ComoboBox.SelectedChanged I think as well.
|
|
|
|
|
Furthermore, if you only care about whether a control changed, you can assign the same event handler to all the "change" events of the controls on the form. Then, if you need to do more, you could use the sender object to do extra things (besides just determining if a control changed). You would just need a generic event handler in the form:
ControlChanged( object sender, EventArgs e )
"Shut up brain, or I'll stab you with a QTip!" - Homer Simpson
|
|
|
|
|
I was hoping there would be something simple like:
RichTextBox t = new RichTextBox();
t.VScrollBar.Value = t.VScrollBar.MaxValue;
You can do something similar in java, but i think its a little more code than this but the same idea.
I can't find how to do this in c#, no topics about it anywhere.
I'm adding text to the RichTextBox programically, like
t.Text += "\r\nHello there";
keep doing things like this and i want the scroll bars to keep scrolling down.
All I could find was t.ScrollToCaret(), but that requires the mouse cursor in the box correct?... either way ScrollToCaret() did not work.
Thanks.
|
|
|
|
|
I have an interesting and stupid problem,
I have a class that is dirived from another class and I want to type cast the first class to the second class somewhere in the program as seen below.
Class A
{
}
Class B
{
}
A FirstObject=new A();
B SecondObject;
SecondObject=(B)A
When I attempt to do this in WebApplication I get
Specific Cast Not Valid.
What am I doing wrong??
John
|
|
|
|
|
Hi John,
I don't think that you can cast classes, even if they derive from the same base class in C# (even tho this is legal in C++). Instead, something like this may get you where you want to go.
Good luck!
Nick.
-----------------------------------------------------------
A Sample Run:
D:\>ClassCasting.exe
ClassA!
ClassB!
D:\>
-----------------------------------------------------------
using System;
namespace ClassCasting
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class ClassCasting
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ClassA oClassA = new ClassA();
ClassB oClassB = new ClassB();
// Can't do this in C# yet!
//oClassB = (ClassB) oClassA;
// But.... you can do this!
CoreClass oCoreClass = oClassA;
oCoreClass.SomeMethod();
oCoreClass = oClassB;
oCoreClass.SomeMethod();
}
}
abstract class CoreClass
{
// Define some common methods here.
public abstract void SomeMethod();
}
class ClassA : CoreClass
{
public override void SomeMethod()
{
Console.WriteLine("ClassA!");
}
}
class ClassB : CoreClass
{
public override void SomeMethod()
{
Console.WriteLine("ClassB!");
}
}
}
|
|
|
|
|
Does anyone have a smart key-generator for generating strings, just by using some kind of string Get_Next_Key() command.
Or some tips to make such a class???
Thank you in advance,
Boudewijn Ector
The Netherlands
|
|
|
|
|
I'm not sure if I understood it correctly, but you could try Guid.NewGuid().ToString()
It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)
|
|
|
|
|
Hi,
I am a beginner at writing services. I need to store information in the registry for starting my service. From what I understand, you could do this in C by creating a CommandLine registry entry. Is there a way to do this in C#. The ServiceBase.OnStart methods takes a string array as an argument. Is the only way to set this argument by adding Start Parameters?
|
|
|
|
|
Good question, i dont know and I'd like to know as well, just replying so that it will notify me if someone else responds. Sorry I was no help.
|
|
|
|
|
Hi,
Does anyone know wether there is some kind of element (like a DATETIMEPICKER) to get the number of the week. For example the second week of February is aprox. week 6. It doesn't matter in wich data type the numebr (string or int\long\short) is returned.
Please help me!
Boudewijn Ector
The Netherlands
|
|
|
|
|
I may not be thinking this through, but how about:
int nWeek = Convert.ToInt32(DateTime.Now.DayOfYear / 7.0);
Nick.
|
|
|
|
|
Hi!
I would like to autostart on my Windows 2000 machines a .NET application I will build. The thing is that the application shouldn't have a GUI or a console window. So I can't make a Windows application (yes I can hide the Form, but that doesn't seem to be such a good idea). Or can I build a Console application but the Console window keeps showing up. Can I get rid of the Console window or should I make a Windows Forms application and then run this.Hide() but this will use memory. Is there some other way of doing this. I'm quite lost. Since I'm a newbie I have probably missed something basic.
|
|
|
|
|
Standard C# Windows application running your code in Main() should work fine. Don't do that Application.Run. That is, if you do not need a message pump.
Rocky Moore <><
|
|
|
|
|
You need a service
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
This stuff will not work if you have'nt Framework installed on the target machine. You better use unmanaged C++ for this application...
|
|
|
|
|
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
<<relatively new="" to="" webservices="" so="" bear="" with="" me="">>
the idea is this, read a recorset into XML object (in C# webservice), VB6 app calls the service gets passed the object thn uses XMLHTTP to read it.
OK problem is i have no idea how to pass it?, i can read XMLHTTP (in VB), and prob. populate XML in C# but the middle?(passing, not wanting to use xml file at all) - can anyone help ?
|
|
|
|
|
Hello,
I am looking for a way in C# to be able to programatically build a list of available classes in the applcation that I can search the list and execute a desired class method based on a passed parameter to the program. I could do this by building a case statement with all available classes, but would like it to be more dynamic.
Thanks
|
|
|
|
|
Hi!
You can try this code snippit, I think it's what you want to do. I made this type of thing before for a Java proggie, and it was even easier in C#! Good Luck!
A few runs look like:
------------------------------
RunArbitraryClasss.exe RunArbitraryClasss.NonRunnableClass arg1 arg2
Unhandled Exception: System.Exception: A class was specified that is not subclassed from ValidRunnableClass!
at RunArbitraryClasss.RunArbitraryClasss.Run(String[] args) in c:\source\automation\runarbitraryclasss\runarbitraryclasss.cs:line 53
at RunArbitraryClasss.RunArbitraryClasss.Main(String[] args) in c:\source\automation\runarbitraryclasss\runarbitraryclasss.cs:line 20
------------------------------
RunArbitraryClasss.exe RunArbitraryClasss.RunnableClass arg1 arg2
I'm a runnable class: arg1 arg2
Here's the source!
--------------------------------------------------------------
using System;
using System.Reflection;
namespace RunArbitraryClasss
{
class RunArbitraryClasss
{
[STAThread]
static int Main(string[] args)
{
RunArbitraryClasss oRunArbitraryClasss = new RunArbitraryClasss();
return(oRunArbitraryClasss.Run(args));
}
public int Run(string[] args)
{
Type [] aTypes = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
foreach(Type oCurrType in aTypes)
{
if(oCurrType.ToString() == args[0] && oCurrType.IsSubclassOf(Type.GetType("RunArbitraryClasss.ValidRunnableClass")))
{
ConstructorInfo ci = oCurrType.GetConstructor(Type.EmptyTypes);
ValidRunnableClass vrc = (ValidRunnableClass) ci.Invoke(null);
string [] passArgs = new string [args.Length - 1];
int i = 0;
for(i = 1; i < args.Length; i++)
{
passArgs[i - 1] = args[i];
}
return(vrc.Run(passArgs));
}
}
throw new Exception("A class was specified that is not subclassed from ValidRunnableClass!");
}
}
abstract class ValidRunnableClass
{
abstract public int Run(string [] args);
}
class RunnableClass : ValidRunnableClass
{
public override int Run(string [] args)
{
Console.Write("I'm a runnable class:");
foreach(string tempStr in args)
Console.Write(" {0}", tempStr);
return(0);
}
}
class NonRunnableClass
{
public int Run(string [] args)
{
Console.Write("I'm a NON-runnable class:");
foreach(string tempStr in args)
Console.Write(" {0}", tempStr);
return(0);
}
}
}
Nick.
|
|
|
|