|
Judah Himango wrote: Is it possible to post your project? I'm pretty sure I could fix it if I've got it here sitting in front of me.
When you run it under the performance profiler, which lines are taking longer? Surely the string comparison and manipulation isn't taking longer on a background thread?
Unfortunately I'm not able to send my project. But I did look at the profiler a little more and can give you some more information on the lines of code that seem to be causing the slowdown.
The dataobject that I pass into the method that takes a long time has a few properties that are List<htmlelement>. I loop through all these and analyze the individual HtmlElements contained within the list.
When I do the following:
<br />
string href = link.GetAttribute("href");<br />
*where link is an HtmlElement that is contained in the list that's a property of the passed in DataObject
or
<br />
if((currentelement.Name == destination &&<br />
currentelement.TagName.ToUpper() == "A") ||<br />
currentelement.Id == destination)<br />
*where currentelement is an HtmlElement that is contained in the list that's a property of the passed in DataObject
When I access the properties of the HtmlElement within the background thread is when the excessive execution takes place. This may have to do with HtmlElement actually being a COM object with the .NET wrapper around it?
Hopefully this gives you some more info I appreciate your time looking into this.
|
|
|
|
|
Yes; since HtmlElement is actually part of a windows forms control, you may not want to access that on a background thread. Also, since the background thread is most likely MTA thread apartment, COM is probably wailing loudly at all this.
Instead of passing a list of System.Windows.Forms.HtmlElement to the background thread, can you pass a copy of only the data you need? For instance, from your snippet it appears you need the href, Name, TagName, and Id of every HtmlElement. So instead of pulling those from the MTA background thread, could you pull them from the UI thread, then pass those strings off to the background worker (perhaps contained in a custom HtmlElementInfo class or something)?
p.s. ToUpper() always allocates a new string. Perhaps you could use this instead:
string.Equals(currentElement.TagName, "A", StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
|
I actually just started to make my own HtmlElement class which only contains the info I need. I think this will solve the problem. Thanks again
|
|
|
|
|
Hello,
I have the following code:
strCmd = "UPDATE [TBl] SET [text] = " + htmldoc + " where id = 11";<br />
OleDbCommand cmd2 = new OleDbCommand(strCmd, conn);<br />
cmd2.ExecuteNonQuery();
Where "htmldoc" is a variable that contains the content of a big html file with lot of quotes extra... so when I execute the code I'm getting an error.
How can I fix that?
Thanks in advance.
|
|
|
|
|
That is not the problem. Quotation marks has no special meaning at all in a string in SQL. The problem is that you forgot the apostrophes around the string.
There are other characters that you should encode, though, as they may appear in the html code. You should encode apostrophes, and if you are using an MySQL database you should also encode backslashes.
---
b { font-weight: normal; }
|
|
|
|
|
Hi
Your problem is, quite possibly, the fact you're using concatenated command text. If the HTML document contains any apostrophe characters, the command will fail. Even worse, if the HTML document contained specially crafted SQL commands, your whole database could be wiped out or an attacker could read your entire database freely. This security risk and bug in your code is known as SQL injection.
Here's how to fix the problem and remove the security risk:
strCmd = "UPDATE [TBl] SET [text] = @HtmlInput where id = 11";
OleDbCommand cmd2 = new OleDbCommand(strCmd, conn);
OleDbParameter htmlParameter = new OleDbParameter("@HtmlInput", htmlDoc);
cmd2.Parameters.Add(htmlParameter);
cmd2.ExecuteNonQuery();
Note that this assumes htmlDoc variable to be of type string.
p.s. next time use <pre> tags to surround your code snippets.
|
|
|
|
|
Hi!
It's embarrasing to ask such a simple question, but is there a simple way to find out how much a NumericUpDown control changed on a ValueChanged event? I know it can be worked around, but I first want to check so that I don't do a lot of extra work.
Regards,
Martin
|
|
|
|
|
Nope, the ValueChanged event does not send the old value, sorry.
Obviously this could be done via a workaround by storing the current value every time the ValueChanged event occurs. You can then compare that against the current value the next time the ValueChanged event occurs.
|
|
|
|
|
The problem is that I have a lot of spinners, and I don't think it's very efficient to create a variable for every single one of them...
|
|
|
|
|
You'd be storing an integer variable for each of them. Unless you have thousands of numeric up down controls, the performance hit would be negligible.
|
|
|
|
|
hi ..
this is my code to set ImageIndex of my button :
ImageList list = new ImageList();
System.Drawing.Icon _icon = new Icon("PRINTERS11.ico");
list.Images.Add(_icon);
button1.ImageList = list;
button1.ImageIndex = 0;
but my Icon is very small in button and i can not resize :
button1.ImageList.Images[0].Size
because it's readonly . How to set size of My icon in button ??
thanks
|
|
|
|
|
You need to copy it onto a bitmap that is bigger, of course this will make it jagged in appearance.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Dear all,
I made a custom control (a type of thumbnail with labels, buttons, ..) and I would like them to be in a list(box). Is this possible? And if yes (please do), how can I do this? Can I add it as some "item object", and add that to the list?
Thank you,
Michael
www.code.ae
|
|
|
|
|
With Windows Forms, you can, but the list box won't show them; it'll just show the .ToString version of the custom control. Note that with the WPF toolkit this is possible.
AFAIK, in order to do that, you'll probably need to inherit a control from ListView and draw your items manually in the list. Not fun.
|
|
|
|
|
I am having great difficulty in marshalling from VB6 to C#. What I need to be able to do is marshall a VB6 Type aka UDT holding a number of fields into C#. Is this possible? If not then I will need to change the legacy code to use a class rather than a UDT.
|
|
|
|
|
Further to my first post above. I went the route of instantiating an object in VB6 that has a number of public fields of type Currency. Successfully created a .NET TypeLib with TLBIMP and can marshall my VB6 object accross to C# but when I tried to access the field value I got an invalid cast exception. Does this mean that I will have to write the ODL information within my C# class rather than use the TLBIMP tool so that I can then marshall the field data from unmanaged type 'Currency' to Decimal?
Or is there an easier way to marshall accross from VB6 to C# and back? Any help will be much appreciated.
|
|
|
|
|
Greetings!
I have been using the System.Management object in a Visual Studio 2003 C# application to access Microsoft DNSS entries. The problem I have encountered is with TXT records which have multiple string entries ("A DNS TXT record can be up to 65535 (0xFFFF) bytes long"). Microsoft supports this just fine, for example, I have a TXT record with the following string values:
KeyA=ValueA
KeyB=ValueB
KeyC=ValueC
KeyD=ValueD
KeyE=ValueE
KeyF=ValueF
KeyG=ValueG
KeyH=ValueH
Microsoft DDNS has no problem with this. But when I retrieve the TXT record with:
(ObjectQuery oQ = new ObjectQuery("select * from MicrosoftDNS_TXTType where OwnerName=...");
the WMI query returns in the following:
OwnerName: aaatesttxtrec.domain.com
RecordData: "KeyA=ValueA" "KeyB=ValueB"
DescriptiveText: KeyA=ValueA
TextRepresentation: aaatesttxtrec.domain.com IN TXT "KeyA=ValueA" "KeyB=ValueB"
(changing the domain name to protect the guilty)
Now, I would be a whole lot less confused if the WMI query had only returned the first value string (or, if the total length of the returned values was less than 64, the maximum length for a single TXT value string).
So why am I only getting the first two (of eight) data strings from the TXT record? Is this a bug in the .NET WMI interface, or am I doing something horribly wrong?
Thank you'all for any help you may be able to offer!
Grant V. Morse
|
|
|
|
|
Hi
i have a made an app where you can draw things like lines graphics etc.,the problem is that when i save it there are no lines in bitmap, though all the physiacal controls like labels are there , but no lines or graphics why?
Sameer Sood
Microsoft Student partner
NIT Durgapur,india
|
|
|
|
|
How do you keep the information about the graphics, and what do you do to save it?
---
b { font-weight: normal; }
|
|
|
|
|
Acrually only lines disappear as they are drawn using GDI, i have saved the start and end point of the line in an rraList, the lines are not coming rest evrything is there, they are redrawn on page invalidation,sohelp if any solution out
Sameer Sood
Microsoft Student partner
NIT Durgapur,india
|
|
|
|
|
Ok, but what do you do to save it, then?
---
b { font-weight: normal; }
|
|
|
|
|
Bitmap bp = new Bitmap(900, 800);
MainPanel.DrawToBitmap (bp,new Rectangle(0,0,900,800));
bp.Save(filename + ".bmp");
Mainpanel is the panel where al work is done and 900*80 is the size
Sameer Sood
Microsoft Student partner
NIT Durgapur,india
|
|
|
|
|
If you would have used the Paint event to draw the lines, as I told you in the previous thread, the lines would have been drawn to the bitmap. As you say that they aren't, you can't be doing that.
I don't mean to sound harsh, but if you don't follow advice, what would be the point of giving any further advice?
---
b { font-weight: normal; }
|
|
|
|
|
hi
I am doing it in OnPaint event and i even redraw them on invalidation, the problem has been solved by christian's suggestion,actually the lines are drawn on screen pixels and objects lie on the panel, so you need to make a bitmap in memory and draw those line son to the bitmap and save it
thanks and regards
Sameer Sood
Microsoft Student partner
NIT Durgapur,india
|
|
|
|
|
What control's paint event is it that you use, then?
Are you using the graphics object that is supplied to you in the event attributes, or are you creating a completely new graphics object? If you don't use the graphics object that is supplied, you will always be drawing to the screen, even when the DrawToBitmap is trying to make you draw to the bitmap.
If you do it correctly, there is no need to draw the lines to the bitmap separately.
---
b { font-weight: normal; }
|
|
|
|
|