|
a.ToString("0.00") should do the job.
For some more information on formatting of numeric strings take a look at this page[^].
www.troschuetz.de
|
|
|
|
|
double a = 1.76543;
Console.WriteLine("{0:F2}", a);
|
|
|
|
|
Hi,
I have a little (very small) app that use too much memory, how can i release resources that are not in use (loaded dll's that are no more necesary for example and all type of garbage that can be disposed) whithout closing my app of course?
When i load a dll can i unload it when it's not needed and my app is in idle?
I saw in a post a few days ago (and can't find it again) an instruction to unload resources when the app is close, if some one can provide me that line of code, this is for making sure i release resources.
Thanx.
|
|
|
|
|
If you want to unload DLLs, you need to load them on a separate AppDomain. How did you conclude your app is using too much memory?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
With windows task manager (CTRL + ALT + DEL).
|
|
|
|
|
Make sure you are calling Dispose() on objects when you don't need them anymore (Controls, Pens, Brushes, Graphics, Bitmaps etc.).
You cannot unload dlls (you would need to load them in separate appdomains which would create even more overhead).
Note that Task Manager does not really show the memory usage of your app, it counts the memory used by the .NET Framework for every application, but in reality large parts of that memory are shared between multiple .NET processes.
|
|
|
|
|
Hi, you're right. Task manager does not really show the memory usage of my app. I tested it, i created a minimal app (a single and empty form) and it uses 10 MB of memory and a single and empty form does not require such amount of memory. My real app loads lots of resources, objects and dll's and it uses 15 MB, it's not a bad score at all!
I'll try Dispose() for objects that are not useful anymore and support this method, thanx for your help.
|
|
|
|
|
Heinz Suez wrote:
Hi, you're right. Task manager does not really show the memory usage of my app. I tested it, i created a minimal app (a single and empty form) and it uses 10 MB of memory and a single and empty form does not require such amount of memory. My real app loads lots of resources, objects and dll's and it uses 15 MB, it's not a bad score at all!
What it comes down to is that getting and returning memory from the system are very expensive operations. Since modern computers have alot more ram that was the case in the bad old days instead of repeatedly asking for small chunks and taking the hit from context switching with the OS every time .net asks for large chunks and holds onto the excess for a very long time unless the OS asks it to return any unused memory the app is holding onto.
|
|
|
|
|
my idea is to communicate one mobile with another mobile ,the first mobile is connected to a system ,when there is a critical event happend in the system then the system send the message to the connected mobile and this mobile is automatically redirect the message to the corresponding second mobile.Is it is possible or not .if it is possible please help me.Also expect code example.
|
|
|
|
|
Just for give you hope. I think everthing is posible in programming. But your work looks a very heavy task. Most mobiles use rs232 ports to comunicate with the pc even those usb mobiles (they use a usb to com converter chip, some of them anyway) so you could start playing with com ports. It's not too much help.
|
|
|
|
|
I was just trying to use some of the System.Net classes and im finding out that some of them are obsolete, but i've seen people all around still using them, and i havent found another class to use instead. What am i supposed to do?
|
|
|
|
|
Here[^] is a link to MSDN's available download of deprecated API members. Most of them provide alternate suggestions.
Deprecated, of course, does not mean deleted. It's a way to get people started on their migration without leaving them holding the bag. Of course, ignoring the deprecation is done at one's own risk.
Good luck.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
I appreciate the link to the ".NET Framework 2.0 Beta 2 Obsolete APIs", it does say which classes and methods are obsolete, and it says also what to use instead, but what if i dont have .NET Fx 2.0, how can my code work in both versions, 1.x and 2.0.
|
|
|
|
|
Had anybody found that DataColumn.Expression sometime is valid and sometime is invalid?
If the DataTable which have a column define DataColumn.Expression binding a DataGrid which has a GridTableStyle, when your edit the grid and change the cloumn value which relation with the column has set 'Expression', the relation column MUST NOT calculate and display a new value.
If I use DataTable.New to create a new DataRow and set value to the columns(not needn't set value to the column has set 'Expression'), and then use DataTable.Row.Add to add a new row, it sometimes can calculate and display a new value. But if I change the column's name and accordingly modify Expression's value, sometimes you surprise to found that it can not work, why?
=== Game is power! ===
-- modified at 23:24 Thursday 29th September, 2005
|
|
|
|
|
Haha..., I got the answer myself.
If you write the sentence
this.dataColumn.Expression="Col1 * Col2";
after
((System.ComponentModel.ISupportInitialize)(this.dataTable)).EndInit();
then it will work right.
But if the code generate by IDE wizzard, it gererate the dataColumn code at the front part, and the sentence '(...).EndInit()' is generate at //Formxx part which must be generated at the end of mothed InitializeComponent(), so, the 'Expression' can not work.
As the said, if you want to use 'DataCloumn.Express' property, the good way is written the code yourself after InitializeComponent().
=== Game is power! ===
-- modified at 1:37 Friday 30th September, 2005
|
|
|
|
|
I'm having difficulty understanding how to explain the following code. Please help...we have to dissect it and explain the operation of the code once it is executed. In advance thank you...
using System; // Rethrowing exceptions:
class MyClass
{
public static void Main()
{
MyClass x = new MyClass();
try
{
string s = null;
x.MyFn(s);
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
public void MyFn(string s)
{
if (s == null)
throw(new ArgumentNullException());
}
}
-ntfirebird-
-- modified at 22:24 Thursday 29th September, 2005
|
|
|
|
|
What's wrong with this code?
It workes well. When the program call the MyFn(s) and execute the throw state then it throw out a exception, in the Main() which make the MyFn(s) call most nearly, the try block catch the exception and goes to deal the exception code 'Console.WriteLine(...)'.
=== Game is power! ===
|
|
|
|
|
You missed the point of his question. He was not wondering why the code would NOT work, he is wondering why the code DOES work.
My guess would be he's taking a .NET class and this is an exersize for the student to explain rethrowing expetions. However, the code in question does not REthrow and exception, it merely throws one and catches it.
I should resist the temptation to help you cheat, but here goes anyway.
The "try" is saying "run the code between the next two braces, and if an exception is thrown during any of it, then "catch" that exception and run the code in the catch block. If no exception occurs, don't run any of the code in the catch block.
Your function MyFn() throws an execption if the parms are null, and the catch block in Main will catch it and run the code in the catch block.
|
|
|
|
|
Hi all,
I'm a VC++ programmer, but is a beginner with the C# language. In VC++, CEdit class has the LineScroll method what used to scroll my Edit to any line. But I do not what method is similar to this in the C# language. I want to ask if you could tell me.
Thanks with best regards.
|
|
|
|
|
Whenever a child form is generated, a set of control box (minimize, maximize, and close buttons) for the child form appears in its parent even though a control box of the child form itself is disabled. Is there any way to disable some or all buttons?
KiT
|
|
|
|
|
Hi folks,
I want to print out data to the screen in two aligned columns. For example the first column is from 0-20 and the second is from 30-50.
It's simple but I don't know how to implement that .
Any idea?
Thanks,
Tommy.
|
|
|
|
|
With my understanding of your requirement, I would suggest take the Datagrid and the specify the length of two column. I would also suggest that use percentage way to represent the size.
Regards,
Jaiprakash M Bankolli
jaiprakash.bankolli@gmail.com
|
|
|
|
|
I wrote a small C# .NET program that has one form and one class (written by my boss) that opens a socket on a remote server. The socket class is able to open the socket and then the class fires an event back to the form when it does. This event calls a function within the Form1.cs class which makes an attempt to post output to a textbox on the form. It goes through the first few lines of code in Form1.Connect(...) but when it gets to the line mytextbox.AppendText("...") is jumps to a random line in the code of the socket class. For the life of me, I can't seem to get around this. I think it has something to do with the thread on which the event is executed and the thread that handles painting/appending text/etc. to the form. Any suggestions would be GREATLY appreciated.
|
|
|
|
|
Take a look at this article[^] on how to call UI thread objects from different threads.
This could be the reason for your problems.
Regards,
mav
|
|
|
|
|
Hello,
I'm trying to copy a treenode and all it's child nodes to the Clipboard.
So far all I can get to happen is to send the selected node text to the clipboard.
I was thinking that setting the clipboard data to whatever dataobject you sent in would send the entire thing over, but apparently not.
So for example I have this TreeNode:
+TheTreeNode
|--Child1
|+--Child2
|--Child2.1
|--Child2.2
|--Child3
What I want to do is click on TheTreeNode and copy that to the Clipboard.
When I paste somewhere, I 'd like to get the exact tree structure, or close to it as text.
I was thinking converting the node to xml then copying that to the clipboard, that seems like a long way around.
I'd appreciate any ideas or directions I could investigate.
Thanks, in advance!
--PhrankBooth
-- modified at 19:46 Thursday 29th September, 2005
|
|
|
|