|
In C++, There is a delete command. But i simular in C#. I am creating program that will have huge ammount of temporary data in memory. I want to get rid of it, without closing process and GC to clean it up. I am also importing WinAPI calls.
|
|
|
|
|
In C# you need to call the Dispose method if you want to manually delete items. GC does some cleaning, but at times even with the combination of the two methods, .NET applications do hog some memory. Another way to minimalize the memory used is to only import libraries that you will be using for that particular class.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
When objects go out of scope, they automatically become subject to garbage collection. You can request a garbage collection to occur but how and when it runs is up to the CLR.
Do some careful research on System.GC.Collect() , System.GC.RunFinalizers() , and possibly System.GC.WaitForPendingFinalizers() .
I've never tried doing this myself but, from what I understand it's generally not a good idea to tinker with garbage collection. GC is an extremely intelligent and streamlined process and futzing around with it usually causes more harm than good.
|
|
|
|
|
Robert.C.Cartaino wrote: When objects go out of scope, they automatically become subject to garbage collection.
They actually become eligible for garbage collection, but won't be collected until the runtime determines there is a need to run a collection cycle.
Robert.C.Cartaino wrote: I've never tried doing this myself but, from what I understand it's generally not a good idea to tinker with garbage collection. GC is an extremely intelligent and streamlined process and futzing around with it usually causes more harm than good.
Yes, you generally should never need to call any of the GC functions. Each time a collection cycle runs, your applications main thread is frozen. The more often you call GC.Collect, the more time your application will spend frozen.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
CLR does the garbage collection automatically so you don't need to delete the objects manually. CLR invokes garbage collector when there is need for memory.
Saksida Bojan wrote: I am also importing WinAPI calls.
If you have P-Invoke calls, you should make sure that it gets removed manually once you finish using it. .NET provides an interface "IDisposable" which can be implemented on your classes and can be used for deterministic clean up. Scott has an excellent article here[^]. Take a look at that.
|
|
|
|
|
hi,
my question is that...how can i determine that what mouse event is occur on particular button?
|
|
|
|
|
By subscribing to the various mouse events possibly?
Dave
|
|
|
|
|
i just want get the mouse event's name which occur on particular button.
|
|
|
|
|
If your using a event that uses the MouseEventHandler, which passes MouseEventArgs, your able to use the MouseEventArgs to find which button was pressed.
For example:
public Form1()
{
this.MouseDown += new MouseEventHandler(Form1_MouseDown);
}
void Form1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Middle)
...
}
Use the intellisense to show all of the available MouseButtons to choose from.
|
|
|
|
|
I'm pretty sure Click won't tell you. But you can handle the Up and Down events to detect your own clicks.
private void button1_MouseDown ( object sender , System.Windows.Forms.MouseEventArgs e )
{
switch ( e.Button )
{
case System.Windows.Forms.MouseButtons.Left : ...
}
}
A while back I was writing a class to help me with it, but it's not yet ready for prime time.
|
|
|
|
|
I'm trying to verify if a character is a letter.
Regex.IsMatch("3", "[a-zA-z]") returns TRUE when it should be FALSE.
What am I doing wrong?
thanx
|
|
|
|
|
why not just use the char.IsLetter(char c) function?
|
|
|
|
|
Apart from what Jimmanuel said, your code returns FALSE for me.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
>>> Regex.IsMatch("3", "[a-zA-z]")
false
Works for me. There must be something else wrong with your code.
|
|
|
|
|
Ok, the following code worked for me. I created a Windows Form with a textbox control and a button. Check it out:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (Regex.IsMatch(textBox1.Text, @"[a-zA-z]") == false)
{
MessageBox.Show("false - input is numeric.");
}
else
{
MessageBox.Show("true - input is non-numeric.");
}
}
}
}
hope this helps.
Jay.
foreach( inch on Jason )
{
Girlfriend.IsHappier();
}
|
|
|
|
|
Hi all. I have build a application in C#. I want to create the next cenario. I want to install the application in all the users and in the same time have in the server a "activity monitor" that tells me who is logged in and what's the state of the application. Could some one give me a pointer or two? Help me to find the way of illumination LOL. Thanks every one.
|
|
|
|
|
There is no easy way, you'll have to write the necessary code at the appropriate places and record the info in a database table.
It shouldn't be difficult but may be time consuming.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Heloo,
How can i read a specific txt file and open a new 'mdb' file that will contain some things that the file has.
For instance,
The File contains:
00000 33333 22222 11111
ID=32 Name=Fox DATE=040208
33333 33333 33333 33333
Number=45 Add=LA Cell=12345678
22222 11111 22222 11111
ID=12 Name=LOLA DATE=020207
and so on....
i want to create a new mdb file that will contain a specific columns (ID,NAME,DATE,NUMBER,ADD,CELL)..
i want that the comp will read the file and ignore the numbers(on the first line,on the third line and on the fifth line) and the comp will add a new line for the mdb file(for example: gil.mdb)
it will very help me..
it is for my HUGE project..
thank you very much..
|
|
|
|
|
System.IO.StreamReader sr = new System.IO.StreamReader("c:\\1.txt");
String Line = sr.ReadLine();
And Look for String.Split to split string to array based on entry. And using String.Substring to get specific chars of specific lenght.
You need to manualy create parser to intercept and convert it to your DB writer
|
|
|
|
|
Hello All,
Array.FindAll, Array.Find and List<t>.RemoveAll() are not available in Silverlight. I'm looking for the equivalent Linq expressions of those methods. I'm also finding the equivalent one but it would be great if you guys can share if you already have something. thanks in advance..
|
|
|
|
|
I think it will work.
public static class ArrayHelper {
public static T Find<t>(T[] array,
Predicate<t> match) {
foreach (var o in array) {
if (match(o)) {
return o;
}
}
return default(T);
}
public static T[] FindAll<t>(T[] array,
Predicate<t> match) {
List<t> list = new List<t>();
foreach (var o in array) {
if (match(o)) {
list.Add(o);
}
}
return list.ToArray();
}
}
|
|
|
|
|
I have a custom button class that has some events. so do i need to remove the button events although though I am disposing the button object.
CustomButton b new CustomButton();
Fom1.Controls.Add(b);
b.MyEvent -= MyEventHandler(myEvent);
Fom1.Controls.Remove(b);
b.Dispose();
CustomButton b new CustomButton();
Fom1.Controls.Add(b);
Fom1.Controls.Remove(b);
b.Dispose();
|
|
|
|
|
I would think that disposing the button would remove the connection to the event procedure.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
|
Hi there,
I am writing an application to run on the compact framework.
The application accepts data from a usb barcode scanner and validate the entry against data held on a file read sequentially.
If the barcode data does not match the data on the file I want my user to be able to decide to accept the entry or not, so far so good.
I have a problem with my messagebox.show selection.
The problem is that the messagebox does not display for longer than 1/2 a second or so and code keeps running until the end of the method without stopping.
ps:The carriage return marks the end data input.
Here is the code:
// Textbox to catch the data from the USB scanner
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if (e.KeyChar == 13) // Catch carriage return from barcode
{
string scannedData = textBox1.Text.Trim();
this.lblBarCode.Text = scannedData;
if (validate_data(scannedData) == false)
{
this.textBox1.Enabled = false;
DialogResult dlgRes = MessageBox.Show("BarCode data does not match, Accept entry ?",
"Validate BarCode",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
if (dlgRes == DialogResult.Yes)
{
// TODO write to output file, don't forget system date !!
}
else
{
// TODO ignore input tidy up
}
}
else
{
// TODO write to output file, don't forget system date !!
}
}
}
catch (Exception z)
{
MessageBox.Show("Error " + z);
}
}
private Boolean validate_data(string scannedData)
{
int i = 0;
string lineData;
lineData = this.lstBoxFiles.SelectedItem.ToString();
i = lineData.IndexOf("-") + 1;
lineData = lineData.Substring(i);
if (lineData != scannedData)
{
return false;
}
else
return true;
}
}
Would any one be so kind as to explain what I am doing wrong.
Thank you
modified on Friday, July 11, 2008 9:55 AM
|
|
|
|