|
thanks for the quick reply, just built it in, for 400 rows it took 34 sec (-1)
For 1000 rows 3m43 (+13)
|
|
|
|
|
My mistake ... amazing ...
I took your last source but used the:
for(i=0; i< listview1 etc )
to correct it for a proper comparrising, i used the foreach routine
it takes for a 1000 rows about 1 second ??? for 3000 a second ???
WOW
and THANKS!!! i was 'rumbling' (if that's a correct word) with it for a couple of weeks
|
|
|
|
|
Interesting, however I'm a bit skeptical. Unless the listView.SelectedItems[index] makes some calls into native code, the for(...) loop should be just as fast -- if not slightly faster -- than foreach. You're sure the for(...) loop was slow even with the StringBuilder? I'd be really surprised if this was the case.
|
|
|
|
|
Actually it all depends on the cost of the termination test in the for loop;
that test gets executed for each iteration, if it entails a method or property lookup,
even when we know the result is or should be constant, it does not get optimized
and moved outside the loop, so it is executed over and over.
The biggest performance mistake in image processing is writing
for (int i=0; i<bitmap.Width; i++) for (int j=0; j<bitmap.Height; j++) ...
since that will probably spend more time interrogating the bitmap's boundaries
size than it does dealing with the actual pixels.
Another big victim is RichTextBox when looping over the text, testing for Text.Length,
which would recalculate the text over and over (and that's why I guess they also offer RichTextBox.TextLength).
-- modified at 17:50 Thursday 9th August, 2007 (patched the less-than sign)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc,
I've been told by people smarter than myself that the JIT compiler will optimize out things like that which can be determined to not changed for the duration of the loop. Seems like this would be one of those cases...
|
|
|
|
|
Judah, I know from experience in debug mode it is not optimized out; I am not sure
what the release situation is. I'll watch it when opportunity knocks.
On the same subject, do you know of an easy way to watch the assembly code generated
by JIT both in debug and in release conditions when programming in C# (using VS Express
Edition). I understood C++ is willing to show a Disassembly window (after setting a
breakpoint?) but C# is not according to this[^]
I would appreciate any means to have a peek at it, even through a complex way; but
obviously, easier would be better.
TIA
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc, I'm afraid I don't know how to do this.
FWIW, here's a detailed discussion about the assembly generated from for vs. foreach[^].
Of course, that's all based on 1.1. Things may have been shaken up and optimized in the CLR v2.
|
|
|
|
|
Thanks for the link. I will study that, and I will try to look with VS Express C++
at assembly code the JIT generated from C#-MSIL too.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
That's what i thougt (i used the c++ version: for(int i ...) but did not consider it to be much less efficient than the foreach loop. But i am greatfull for this solution !! Thanks
3.30 sec -> 1 second ;P jippie
|
|
|
|
|
I just started learning .Net and C#.
I come from C++ background.
When I declare a class vble
// class A is defined;
A a;
a = new A();
This object a is allocated in heap right? and its a reference type?
It seams all class variables are reference types. And it looks like a class pointer to me when I relate to C++.
Any good article?
thanks,
Misha
Evil traiumphs when good people sit quiet...
|
|
|
|
|
|
misha_grewal wrote: This object a is allocated in heap right? and its a reference type?
Correct.
It seams all class variables are reference types.
That's right. A class is always a reference type, and a struct is always a value type.
And it looks like a class pointer to me when I relate to C++.
A reference is implemented as a pointer, but it's easier to use in the code. You don't have to dereference a reference to get to the object, as you do with a pointer.
---
single minded; short sighted; long gone;
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
int n = 0;
textBox2.Visible = false;
textBox1.Visible = false;
while (n<100)
{
Thread.Sleep(100);
n++;
}
}
when I click the button, the textBox1 and textBox2 still visible! After 10sec, they are invisible,why?
NOTE:this code run in PPC, if run in WINDOWS, that two textBox will invisible after I click the button,is difference in PPC,why?
|
|
|
|
|
while (n<100)
{
Thread.Sleep(100);
n++;
}
You are making your UI sleep for 10 seconds -- once it gets out of the loop, the graphics object gets invalidated and the Paint handler gets to repaint your boxes (as invisible).
|
|
|
|
|
Hello,
You have to call:
textBox2.Visible = false;
textBox1.Visible = false;
Application.DoEvents();
bevore you start the Thread.Sleep
All the best,
Martin
|
|
|
|
|
How can i print an image using GDI+ in C# in avery dennison ap 4.4 printer. It is a ticket printer which accepts 3.9cm X 7.9 cm sheet?
|
|
|
|
|
Does anything in the System.Windows.Forms (such as the PrintDialog class) work?
If not, and you need to go outside the .NET framework for this, you can use P/Invoke[^] to call Win32 APIs.
|
|
|
|
|
I tried it came in reverse order with lot of space left on top. It should exactly match the ticket. So i need to adjust the printoutput same as ticket size. All these are readonly properties. I saw one PrintTicket class(in System.Printing namespace and in 2.0 all these are in System.Drawing.Printing namespace) in .Net framework 3.0. But there also same issue. print is coming in 3 tickets instead of one.
|
|
|
|
|
Hi guys,
I have tried numerous ways to export a report to PDF and I keep failing. Please help me, I am trying to export a crystal report from crystal report viewer to .pdf format automatically. Here is my code, it creates the report but it is not a .pdf and doesn't open in acrobat.
O_Report.Load(@"C:\Documents and Settings\sameer.patwa\My Documents\Project Files\POS\POSPymt\Invoice.rpt");
O_Report.Database.Tables[0].ApplyLogOnInfo(LogInfo);
pv.Value=SlsId;
pvs.Add(pv);
O_Report.DataDefinition.ParameterFields["Ad_Parameter1"].ApplyCurrentValues(pvs);
ExportOptions exp= new ExportOptions();
ExcelFormatOptions excelFormatOpts = new ExcelFormatOptions ();
DiskFileDestinationOptions dsk = new DiskFileDestinationOptions();
exp = O_Report.ExportOptions;
exp.ExportDestinationType = ExportDestinationType.DiskFile;
exp.ExportFormatType=ExportFormatType.PortableDocFormat;
dsk.DiskFileName = @"C:\" + SlsId + ".pdf";
exp.DestinationOptions = dsk;
O_Report.Export();
sasa
|
|
|
|
|
The following method and code extract shows how I return to a browser in pdf format. I am not using the viewer in this example.
Stream ReportStream = GenerateReport(rptFileName, ds, ParmList);
MyPage.Response.Clear();
MyPage.Response.Buffer = true;
MyPage.Response.ContentType = "application/pdf";
MyPage.Response.AddHeader("Content-Length", ReportStream.Length.ToString());
byte[] ByteReport = new byte[ReportStream.Length];
ReportStream.Read(ByteReport, 0, (int)ReportStream.Length);
MyPage.Response.BinaryWrite(ByteReport);
MyPage.Response.Flush();
MyPage.Response.Close();
private Stream GenerateReport(string rptFullFileName, DataSet dsReport, ArrayList alRptParam)
{
ReportDocument crReport = new ReportDocument();
//Load the report file (name.rpt)
crReport.Load(rptFullFileName);
// Load the parameters if any
for (int index = 0; index < alRptParam.Count; index++)
crReport.SetParameterValue(index, alRptParam[index]);
// Set the datasource we use datasets
crReport.SetDataSource(dsReport);
return (crReport.ExportToStream(ExportFormatType.PortableDocFormat));
}
Tom
|
|
|
|
|
Thank you for your response Tom. I appreciate it.
I got my code to work, the problem was with my filename, it had a colon in it which was throwing it off.
sasa
|
|
|
|
|
I wish to create a property of a control which is an array of Images, such that I can add, edit and delete images in the VS2005 property window. I've created the property as:
private Image[] _myImages;
public Image[] MyImages
{
get { return _myImages; }
set { _myImages= value; }
}
The property appears in the property window, with a button that brings up the Image Collection Editor (empty, as expected). However, when I press the add button, I get the message "Cannot create an instance of System.Drawing.Image" because it is an abstract class."
If I prepopulate my array with "private Image[] myImages = new Image(3)"
It shows up as an array tree with three (none) images. I can edit each of these (good), but unless I set all of them to something (non null), I am unable to save the form (error is "Code generation for property 'MyImages' failed. Error was: 'Object reference not set to and instance of an object."
I have no trouble includeing a single Image as a property, nor do I have any trouble with an array of strings.
Any Indication as to what I may be doing wrong?
|
|
|
|
|
I'm not certain what to do here, but I have a few tips that might point you in the right direction.
I bet that the key is some attributes on your property that tell Visual Studio what to do with it. I recommend looking at the source code for existing controls that hold arrays or lists. For example, look at the attributes on System.Windows.Forms.ImageList and see how it's being done.
Alternately, to diagnose errors like these, you can attach a VS debugger to Visual Studio, then get the first Visual Studio to throw an error. The debugger should step into your code and show you what piece of your code is throwing an error up to the designer. Read more about this here[^].
|
|
|
|
|
HOW TO CHANG BACKGROUND COLOR IN 1 ROW
q1: I HAVE MANY ITEM 11 ROM BACKGROUND COLOR IS RED BUT I HAVE 2 ROW TO CHANG
BACKGROUND ONLY HOW?
q2: HOW TO HIGHLIGHT LIST VIEW IN EACH ROW
thanks
|
|
|
|
|
First of all, stop writing in all caps. That's the quivalent of shouting on the web. Don't do it.
Secondly, I realize English may not be your first language, but in any event, your sentences are so broken it's difficult to understand what you're asking. Perhaps you could more carefully craft your question in English, or post on a board of your native tongue.
To answer your questions, I will try my best to understand what you're asking.
abcomp01 wrote: q1: I HAVE MANY ITEM 11 ROM BACKGROUND COLOR IS RED BUT I HAVE 2 ROW TO CHANG
BACKGROUND ONLY HOW?
It sounds like you're asking how to change the background color of an item. What kind of item? I assume from your 2nd question that you're wondering how to change the back color of a Windows Forms ListViewItem. If so, look at ListViewItem.BackColor property.
abcomp01 wrote: HOW TO HIGHLIGHT LIST VIEW IN EACH ROW
I don't know what you mean by this. Can you clarify?
|
|
|
|
|