|
IIRC explicitly calling GC.Collect() is generally a bad idea. The deal is that it will encourage the garbage collector to promote objects that survive collection to a higher generation. The higher generations are collected less aggressively - which has obvious performance implications.
|
|
|
|
|
You recall correctly. There aren't many occassions, (I can't think or any offhand), where you should call it - let the runtime determine this.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
You may consider GC.Collect() when you want to get an optimal and/or repeatable
starting condition, examples:
- application has busy and idle periods, and wants to off-load as much work as possible
from the busy to the idle periods
- application is going to be observed/measured (as in the Setup method when using NUnit),
say for performance measurements.
And yes, these are exceptional situations.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Garbage collection in .NET is not based on frequency. Instead, it is a sophisticated algorithm that will collect the object at some point after the object has become eligible for collection.
Have a read of this[^] article.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi
I am writing a UserControl that contains 20 similar 'other' controls. My basic control is also a usercontrol consisting of a Panel and a Button inside a parent Panel.
I need to create 20 of these simple usercontrols onto a bigger Usercontrol.
I have done this by using a array of this.
>> ucPanels[] iPanels = new ucPanels[20];
I call this method :
>> private void createMainPanel()
{
int z = 1;
for (int i = 0; i < 20; i++)
{
iPanels[i] = new ucPanels();
iPanels[i].Name = "myPanel" + i.ToString();
Controls.Add(iPanels[i]);
iPanels[i].Location = new System.Drawing.Point(z, 5);
iPanels[i].Click += new System.EventHandler(iPanels_Click_1);
iPanels[i].MouseDown += new System.Windows.Forms.MouseEventHandler(iPanels_MouseDown_1);
//iPanels[i].Size = new System.Drawing.Size(50,84);
z += 51;
}
}
private void iPanels_Click_1(object sender, EventArgs e)
{
for (int i = 0; i < 20; i++)
{
// I cannot reach this event
}
}
Is there anything wrong with my code as I cannot call my event iPanels_Click_1
Thanks
Amien
Amien
Cape Town
South Africa
|
|
|
|
|
If the panel is docked and filling the usercontrol you'd probably have to
add an event handler for the panels click on the usercontrol and then
call the usercontrols click event from there.
If it' stuck, DO NOT pull harder!
|
|
|
|
|
Hi,
How can i search in all columns of a table for a word that the user types in a textbox? some code pls?
|
|
|
|
|
DataTable have a Select() method which allows you to filter DataTable and returns DataRow array.
|
|
|
|
|
Aproximately:
...
DataTable dt = ...
string sText = txtInput.Text;
foreach(datacolumn in dt.columns)
{
if( typeof(datacolumn) == string )
{
DataRow[] oRows = dt.Select(DataColumn.Name + " = " + sText);
if( oRows.Count > 0 )
{
//Do wat you have to do
}
}
}
Visit my blog at http://dotnetforeveryone.blogspot.com
|
|
|
|
|
I'm doing a little thing, trying to write an application to draw fractals. I've got the complex numbers down, the algorithm is working.
But, it's taking a long time, so I figured "Hey! Why not use multi-threading?"
My idea is to have a Control task which creates and fills up a Queue with Points, reports progress and spawns and controls 2 more tasks (either Threads or uses a ThreadPool), which in turn do the calculations (they take the Point they need to work on from the Queue as long as the Queue isn't empty). By using the Queue, I'm 100% that the Threads never work on the same pixel; they only work on the Queue, and lock it when they need data.
But the problem is, even though they never work on the same pixel, they work on the same Bitmap object. Which is bad, because it cannot be accessed at the same time from multiple threads (even if they want something different from it).
I can't inherit the Bitmap (sealed), I can't inherit Image (internal constructor), so any attempts at creating my own image class have failed. The one that didn't involved a simple array of Colors, but recreating a Bitmap from that at the end takes way too much time.
So I'm in the dark... I don't know if there's a trick I could use to work with that Bitmap, or perhaps a different image class I could use (that can be easily drawn on a form)... Please help.
|
|
|
|
|
Don't inherit the Bitmap, encapsulate it. Make a class that holds the Bitmap in a variable, and synchronises SetPixel calls on it.
Another alternative is to have a result queue, where the threads put their results, which the main thread then can read and put in a Bitmap. (It would have to be synchronised, of course, just like the task queue.)
It sounds like a lot of overhead to queue single pixels, though. You should consider handling blocks or lines of pixels.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Encapsulating the Bitmap doesn't help... I found that it will still throw exceptions in that case (object is in use by another thread).
But I DID solve the problem... I can create a Bitmap quickly from an array of bytes using Bitmaps LockBits and UnlockBits. I made a nice little class that I can access from multiple threads and that can quickly create a Bitmap.
SetPixel and GetPixel simply suck, as it turns out. They're too slow and cumbersome.
|
|
|
|
|
Shaamaan wrote: Encapsulating the Bitmap doesn't help... I found that it will still throw exceptions in that case (object is in use by another thread).
Then you only read half of what I wrote. Just encapsulating an object doesn't help a bit if you still allow unsynchronised access to it.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Hi.. this is a problem i've tried to figure out for a long time and i have searched google, MSDN, Businessobjects forums without any luck.
and i'm aware this might be offtopic but the project is written in C# and there's no crystalreport forum.
the problem is, i have a crystalreportviewer which shows a report with a group tree. if i click on a node on the group tree the viewer scrolls to the selected group. but only the header part of the group is scrolled into view. not the details, so the user would have to scroll down.
when i view the report in Crystal Reports 10 Professional. which was used to create the report,
it works fine, clicking on a group tree puts the group nicely at the top of the page so the underlying details are shown. we used to have an old OCX on a webpage. and that scrolled the whole group into view too. so i have ruled out the actual rpt file.
if i maximize the window and view the report in 80% this offcourse is no problem because i can see the whole page. but that's unfortunately not an option.
so does anyone know how to get the selected group to display at the top of the view?
If it' stuck, DO NOT pull harder!
|
|
|
|
|
hy everyone!
i do have a problem:
i do have a template which looks like that (just an example line)
tag1xxxx tag2xxxxxxxxx tag3xxxx tag4xxxxxxxxxxxxx tag5xxxxxxxx
the tag1, tag2 is the tagname i want to find in the output which should be replaced by it's value. the x afterwards is used for formating. this means tag1 has to be 8 char long, tag2 13 char etc.
so now i do want to replace tag1 for example with peter. peter is just 5 char long, so the last 3 x have to be replaced with spaces to keep the table with its format. but i can't just replace x by space because this would kill all the others.
my program should be something like
<br />
for (i=1; i<tags; i++)<br />
{<br />
Text.Replace("tag" + i, tagvalue);<br />
}<br />
examples / szenarios:
tag1xxxx tag2xxxxxxxxx tag3xxxx tag4xxxxxxxxxxxxx tag5xxxxxxxx
*) tagvalue1 < tag1 (tagname) => replace x by space and add spaces to the value before replacing the tagname tag1
*) tagvalue1 = tag1 (tagname) => replace x by space and replace the tagname tag1
*) tagvalue1 > tag1 (tagname) => remove length(tagvalue)-length(tagname) x and replace the remaining x by spaces and finally add the vale instead of the tagname.
do you have any good solution how to do this without a lot of lines? because this szenarios have to be placed in the loop described above.
thanks!
Stephan.
|
|
|
|
|
Hi .,
I have DataTable filled with the data. Now I want to change the
datatype of one of the column to sqldbtype.datetime .Is it possible to achieve?
Thanks
Navneet H
Develop2Program & Program2Develop
|
|
|
|
|
how to set the precision of double type in c#?
by default, 1/3=0.33333333333333, output from c#, If I want to the output is only 0.33, that means the output is only two number after the point.
thanks
|
|
|
|
|
double type makes round by defect. If you wan't round you have to use real...
Visit my blog at http://dotnetforeveryone.blogspot.com
|
|
|
|
|
If it is just the display output you want :-
static void Main(string[] args)
{
double d = 1.0 / 3.0;
Console.WriteLine(d);
Console.WriteLine("{0:0.00}", d);
}</code>
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
Hi,
Will i be able to use delegates in this code without inheriting the different classes.
If not what is the advantage in using delegates in this code?
Is delegate more useful when we are dealing with multiple forms and events?
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
public delegate void nameofdelegate();
class Program
{
public static void function1()
{
Console.WriteLine("will be called by the delegate");
Console.ReadLine();
}
}
class newprogram:Program
{
public static void function2()
{
Console.WriteLine("second delegate");
Console.ReadLine();
}
}
class mainprogram:newprogram
{
static void Main(string[] args)
{
nameofdelegate delobj = new nameofdelegate(function1);
nameofdelegate delobject = new nameofdelegate(function2);
delobj();
delobject();
}
}
}
Thanking you
k
|
|
|
|
|
new2pgrmg wrote: Will i be able to use delegates in this code without inheriting the different classes.
Yes. You just have to specify the class name to access the methods:
nameofdelegate delobj = new nameofdelegate(Program.function1);<br />
nameofdelegate delobject = new nameofdelegate(newProgram.function2);
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Thank You Sir that was very helpful.
Can you answer these also please
what is the advantage in using delegates in this code?
Is delegate more useful when we are dealing with multiple forms and events
Thanking You
k
|
|
|
|
|
new2pgrmg wrote: what is the advantage in using delegates in this code?
None.
Delegates are used when the method to call is not known when creating the code that will call it, or when the same code will be used to call different methods.
For example, you use a delegate when calling the List<T>.Find method:
List<int> list = new List<int>(new int[] { 1, 2, 3, 4, 5 } );<br />
int firstEven = list.Find(delegate(int x) { return x % 2 == 0; } );
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Hi all,
I want to overwrite an existing file (acttually, it's an excel file). But i don't know whether it's in use or locked by another process or not.
Is there a way to check that.
Thanks.
|
|
|
|
|
use a file which is locked u will get an exception
handle that exception using try catch block ...
Exception handling tat's all
|
|
|
|