|
bobmitch wrote: This will always use the parent intersect function and not the appropriate child function
That is because in the derived classes you have used the "new" qualifier on the method declaration which tells the compiler to hide the implementation. The reference to the base does not know about your "new" implementation.
You need to declare the method as virtual on the base, and override on the derived classes.
public virtual Intersection()
{
}
...
public override Intersection()
{
}
|
|
|
|
|
Class A{...}
void main()
{
Object o;
o=new int();
o=new String();
o=new A();
}
What will o eventually point to?
if eventually o point to A, then what happen to int and String object?
Thanks in advance
|
|
|
|
|
loke6258038 wrote: What will o eventually point to?
An instance of class A
loke6258038 wrote: if eventually o point to A, then what happen to int and String object?
The garbage collector will eventually get them.
|
|
|
|
|
Hi everybody,
I work with big XML files and i want to free up the memory after a have finished working with one file.
If i set the reference of the XmlDocument to null the memory will be free from the GC. But how can i free the memory immediately when i don't need any more the reference?
Thanks.
|
|
|
|
|
Noemi Katinka,
Call "thing.Dispose()"
Regards,
Gareth.
|
|
|
|
|
how big are these files ? You'd have to force GC, which is usually a bad idea, and can mess up memory management in general in your app. XML files are just text, there's nothing to Dispose.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Don't mess with it. Let the garbage collector do its job when the memory is needed. You can cause more problems running a garbage collection manually by ending up promoting other objects to higher generations.
|
|
|
|
|
You could use an XmlReader to parse through the document without having to load the entire document in memory. I've found this useful when loading records from very large XML files (i.e. 100Mb and above).
|
|
|
|
|
I have a DataReader that was working until I changed some code around, now it just skips over the While(reader.Read()) loop for some reason.
OleDbConnection oleDbConnection = new OleDbConnection(str2);
string strCom = String.Concat("select Unit from Units where Unit=\'", strUnits, "\'");
OleDbCommand oleDbCommand = new OleDbCommand(strCom, oleDbConnection);
OleDbDataReader HpReader= null;
oleDbConnection.Open();
HpReader = oleDbCommand.ExecuteReader();
while (HpReader.Read())
{
if (strUnits == "Length")
{
comboHD.Items.Add(HpReader.GetString(0));
}
else if (strUnits == "Velocity")
comboFV.Items.Add(HpReader.GetString(0));
else if (strUnits == "Kinematic viscosity")
comboKV.Items.Add(HpReader.GetString(0));
}
HpReader.Close();
oleDbConnection.Close();
|
|
|
|
|
The Read method returns false if there are no records. Check the results of your command externally. And because I am a pedantic A&* you should really be consistent in your variable naming casing.
(I would focus on the value of strUnits as it seems to be a good candidate for the empty results.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
string strCom = String.Concat("select Unit from Units where Unit=\'", strUnits, "\'");
changed query:string strCom = String.Concat("select Unit from Units where Unit="\", strUnits, "\"");
use changed query it will work.
|
|
|
|
|
I have contacts A, B, C
A is related to B
A is related to C
B is related to C
Data Base table are
Contact(IDContact)
ContactRelation(IDContactRelation, IDContact(FK), IDRelcontact(FK))
then I wanted to show this relationship diagramatically
please somebody provide me solution for it
rasana
|
|
|
|
|
Sure, I accept credit card payments from my website.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
|
Be careful, your teacher is probably reading those forums also.
|
|
|
|
|
If i could get some sample on how to draw the elipses and connector to those ellipses that is also fine to start
rasana
|
|
|
|
|
I'm using an invoke on a form to update the UI from a backgroundworker thread.
The problem is that the application slows down enourmously - in fact it is around >50 times faster when the UI is not being updated!
Using a delegate has the same effect.
Can anyone give me some pointers to an alternative to updating a UI from a backgroundworker that is fast.
Thanks in advance.
Guy
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Updating UI is an extremely slow process compared to computation. The most effective way to update a UI is to do so no more than a human would reasonable expect. For example, there is no reason to update a text box more than 2 times per second, and even then that is overkill. Put in a throttle that will ignore your UI update invoke if it has already happened within a given unit of time and you will see a dramatic increase.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Thanks - that helps.
I was assuming that updating a UI was fast and I was just missing something.
Once every two seconds should be fine for my application.
I suppose C++ would be the direction to go for this sort of speed?
(A direction I have no intention of heading in just yet...)
Regards
Guy
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
GuyThiebaut wrote: I suppose C++ would be the direction to go for this sort of speed?
No, not really. You're still using slow controls that draw themselves to the screen. The language you use isn't going to make that much of an impact on the speed of the update.
|
|
|
|
|
Thanks for the information - coming from a database background this is all new stuff for me.
I'm guessing the Windows API is having to do a lot of work to update a form.
I popped a timer into the application and set the Tick event to update the UI - works like a treat now.
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
The problem with updating the UI is that only the UI thread can access the controls in the UI, so if you do it from a background thread, you are actually sending a message to the UI thread to do the update. This of course means a lot of overhead.
You can use a synchronised queue to send the information more efficiently. Create a queue in the UI thread and send along a reference to it to the background thread. Put updates in the queue from the background thread, and use a timer in the UI thread to look for new information in the queue.
SynchronisedQueue<string> queue = new SynchronisedQueue<string>;
IQueueWriter<string> writer = queue;
writer.Enqueue("something");
string info;
while (queue.TryDequeue(out info)) {
labelInfo.Text = info;
}
Instead of a string you can of course use any type you like, perhaps make your own class with any information you need to send between the threads.
Here's the synchronised queue:
public interface IQueueReader<T> {
bool TryDequeue(out T value);
}
public interface IQueueWriter<T> {
void Enqueue(T value);
}
public class SynchronisedQueue<T> : IQueueReader<T>, IQueueWriter<T> {
#region Private variables
private Queue<T> _queue;
private object _sync;
#endregion
#region Constructor
public SynchronisedQueue() {
_queue = new Queue<T>();
_sync = new object();
}
#endregion
#region Properties
public int Count { get { lock (_sync) return _queue.Count; } }
#endregion
#region Methods
public void Clear() {
lock (_sync) {
_queue.Clear();
}
}
public void Enqueue(T value) {
lock (_sync) {
_queue.Enqueue(value);
}
}
public bool TryDequeue(out T value) {
lock (_sync) {
if (_queue.Count > 0) {
value = _queue.Dequeue();
return true;
} else {
value = default(T);
return false;
}
}
}
#endregion
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Wow, thanks that is genius work.
I don't fully understand it at the moment but it is starting to make sense and is pretty cool.
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Can this be done? I have a need to use a console application in the background with a c# gui feeding commands and reading output from it.
similar, but not limited to something like executing ping, feeding it the url or ip, then reading the responses. Any help would be appreciated.
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Can you be more specific on what is going on in the background? We run console apps from web pages at my new job so I know it can be done. (Unless I have some weird definition of a console application.)
|
|
|
|