|
Thanks for this explanation. I think i got the idea.
But let's go back to the pactual roblem this thread is about.
Today, i found a similar problem in my application. I have an ArrayList where i store instances of a certain class X. Each of this instances possesses a Queue that is pretty big. For example, if i add 2 instances of class X to the ArrayList the memory usage increases by 4MB.
When i remove the instances from the ArrayList, they are collected by GC (tested that) but the memory usage doesn't decrease. But also it doesn't increase when i add two new instances of class X to the ArrayList. Only a third object increases memory usage.
Could it be that the memory is freed when the instances of class X are collected by GC but somehow remains attached to my application?
|
|
|
|
|
I Want to write a program that acts like Office Tool Bar. I need to be able set the main Form to be dockable and make sure it always stays on top (adjust the main screens client area)
Possible?
Any suggestions on a starting point for
camasmartin
hobby programmer
|
|
|
|
|
depends on a) whether it should be a dll or some suchlike thing so you can import it into other things, b) how well you want it written.
do a search in these forums for things of the same subject, there was someone who took the time to write one before and explained it quite. alas i cannot remember their name.
i ended up writing my own so it could be called as a function into my stuff, and i'd know what went into it. alas i haven't yet worked out how to successfully put it into a function!
you'll need to do something like callling your code into child window, and performing some calculations to see where it is on the screen, where the parent is on the screen; and so how far they are from ech other. then, make variables like how much you want the margin to be etc. i found when you pushed it up near the edge it would flicker as it was constantly repositioning, but it was suited to that task. you're probably better looking for someone elses also, as mine only copes with parent and child mdi forms, and as yet i would have to copy and paste the code.
also, mine wouldn't snap child forms. but do post how you get on.
-------------------------------------------------------
ithium is the best.
'Science without religion is lame, religion without science is blind.' --Albert Einstein
'The pioneers of a warless world are the youth who refuse military service.' --Albert Einstein
|
|
|
|
|
Help! I am getting the following error message when trying to retrieve data using a web service in a C# app. At first before getting this error message, I was able to retrieve data at times (not changing any of the code) and then now it is only giving me this error message when trying to retrieve any of the data. Does anyone know why I am now getting this error message?
---------- Error Message -------------
An unhandled exception of type 'System.Web.Services.Protocols.SoapException' occurred in system.web.services.dll
Additional information: Server was unable to process request. --> Catastrophic failure
|
|
|
|
|
Check the server trace log, if enabled. If not, enable it by setting <trace enabled="true" /> in your Web.config file. Look for the exact exception that is occuring in /trace.axd (rooted from whatever your web application is). This will give you more details.
For one thing, make sure you're disposing any IDisposable implementations when you're done and that your closing connections, files, etc. Your problem may have nothing to do with those scenarios, but they are common. Just because objects are GC'd automatically doesn't mean that all resources (i.e., native resources like file handles) are released.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks That definitely helped and now the problem is fixed.
|
|
|
|
|
Ok, here's my situation. I am retrieveing an ImageURL from the database. There is a column retrieved, known as "flash" (bit column). Basically if "flash" has a value of 1, then I would have to render something with "<object ...="" <="" object="">" at the front end. This is where my problem comes in. How do I do that ?
in the old asp, I would do something like..
<%if rs("flash")=1 then%>
response.write("xxxx")
<%end if%>
Any idea ?
I got all the repeater working fine...
|
|
|
|
|
If you're developing a WebControl , you can do this in your Render override using some property that is exposed as a public property, or using a definition from the database.
If you're doing this inline with the ASP.NET page (in the .aspx file), you can still do something similar, but a WebControl derivative is much easier to work with.
This really belongs in the ASP.NET forum, however.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Actually here's the sample code which I have difficulty for..
<asp:repeater id="someRepID" runat="server">
<ItemTemplate>
<asp:Panel ID="somePanelID" runat="server"></asp:panel>
</ItemTemplate>
</asp:repeater>
Now Panel is suppose to contain 2 type of template.
Template 1:- (gif/jpg images)
<a href=".."><img src=".."></a>
Template 2:- (swf flash images)
<object ...><value src="..">..</object>
And those two template is determine by a bit column. so I know which to display.
Now, with the above sample code, I got the Panel displaying when i put it outside of the repeater block. But when it's inside it doesn't work. Sorry if this is in the wrong forum, because code-behind language is c#. Any help appreciated....
|
|
|
|
|
The best way is to not use the Panel in the FCL, but instead to extend it with your own class and in your override to Render do something similar to what I posted before. There are ways to do this using ASP-style syntax but it's cludgy and you have little control over it.
So, you could either define properties in your derivative class which would be set by data-binding expressions by the parent control (like <%# DataBinder.Eval(Container.DataItem, "flash") %> ) or have your derivative class get the current data item, which I can't remember how to do off-hand (the answer's in the .NET Framework SDK, though).. Once you get that bit you need, just conditionally output the string as you have above in your override for the Render method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a client using HttpWebRequest to send a POST request to a Web service. Using a TCP sniffer, I can see that the last character is truncated, making the web service wait for the missing last character until it times out. Here is the code:
HttpWebResponse authResponse = null;
StreamReader responseStreamReader = null;
try
{
byte[] requestBytes = Encoding.UTF8.GetBytes(this.txtRequest.Text);
HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(new Uri(this.txtAuthURI.Text));
authRequest.Method = "POST";
authRequest.Credentials = CredentialCache.DefaultCredentials;
authRequest.ContentType = "text/xml";
authRequest.ContentLength = requestBytes.Length;
Stream requestStream = authRequest.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Flush();
requestStream.Close();
authResponse = (HttpWebResponse)authRequest.GetResponse();
responseStreamReader = new StreamReader(authResponse.GetResponseStream());
StringBuilder sb = new StringBuilder();
sb.AppendFormat("HTTP Status: {0}{1}", authResponse.StatusCode, Environment.NewLine);
this.txtResponse.Text = sb.ToString();
}
catch (Exception ex)
{
MessageBox.Show(this, "Cannot send Auth Request: " + ex.GetType().ToString() + ": " + ex.Message);
}
finally
{
if (null != responseStreamReader)
{
responseStreamReader.Close();
}
if (null != authResponse)
{
authResponse.Close();
}
}
I have tried using a StreamWriter, to no avail. Does anyone have an idea of what is wrong here?
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Buffering the entire content can lead to problems. Try using smaller buffers (4096 is typically a good buffer size) and getting bytes and writing to the request stream in a loop till all bytes are sent. I've seen similar problems like this with such a large buffer (and there were some limits in older TCP/IP implementations in Windows, but I don't know if these apply now). I do find it weird that it's just the last character, though. Using a smaller buffer is definitely worth a try, though.
Out of curiousity, why not just create a Web Service proxy (either using VS.NET to generate it from WSDL, which also gives you async capabilities, or deriving manually from HttpWebClientProtocol or SoapHttpClientProtocol depending on your service implementation and your requirements)?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have been coding a media player for a school project with GDI+ and C#. My app displays alot of bitmaps to change the colors of the player (eye candy). If I have another app window open (ex. Calculator) on top of my player and I move the calculator around, my player window draws really slow and the remnants of the calculator window are displayed over the bitmaps for a short period before a complete refresh. My mem usage for the player is always around 30M - 50M which seems like alot to me for an app that can only change skin textures. My OnPaint creates a bitmap to draw to before refreshing the screen.
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
Image screen = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);<br />
Graphics graphics = e.Graphics;<br />
Graphics temp = Graphics.FromImage(screen);<br />
<br />
GraphicsPath texturePath = new GraphicsPath(new Point[] {new Point(30, 50),
new Point(30, 50),<br />
new Point(30, 30),<br />
new Point(50, 30),<br />
new Point((this.Right - this.Left) - 20, 30), <br />
new Point((this.Right - this.Left) - 20, 30),<br />
new Point(this.Right - this.Left, 30),<br />
new Point(this.Right - this.Left, 50),<br />
new Point(this.Right - this.Left, (this.Bottom - this.Top) - 20),<br />
new Point(this.Right - this.Left, this.Bottom - this.Top - 20),<br />
new Point(this.Right - this.Left, this.Bottom - this.Top),<br />
new Point((this.Right - this.Left) - 20, this.Bottom - this.Top),<br />
new Point(50, this.Bottom - this.Top),<br />
new Point(50, this.Bottom - this.Top),<br />
new Point(30, this.Bottom - this.Top),<br />
new Point(30, (this.Bottom - this.Top) - 20),<br />
new Point(30, 50)},<br />
new byte[] {(byte)PathPointType.Start, <br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier, <br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier, <br />
(byte)PathPointType.Line, <br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line});
<br />
GraphicsPath navButtonsPath = new GraphicsPath(new Point[] {new Point(this.panel1.Left, this.panel1.Top),<br />
new Point(60, this.panel1.Top),<br />
new Point(60, this.panel1.Top),<br />
new Point(50, this.panel1.Top),<br />
new Point(50, this.panel1.Top + 10),<br />
new Point(50, this.panel1.Top + 90),<br />
new Point(50, this.panel1.Top + 90),<br />
new Point(50, this.panel1.Top + 100),<br />
new Point(60, this.panel1.Top + 100),<br />
new Point(this.panel1.Left, this.panel1.Top + 100),<br />
new Point(this.panel1.Left, this.panel1.Top + 110),<br />
new Point(60, this.panel1.Top + 110),<br />
new Point(60, this.panel1.Top + 110),<br />
new Point(50, this.panel1.Top + 110),<br />
new Point(50, this.panel1.Top + 120),<br />
new Point(50, this.panel1.Top + 200),<br />
new Point(50, this.panel1.Top + 200),<br />
new Point(50, this.panel1.Top + 210),<br />
new Point(60, this.panel1.Top + 210),<br />
new Point(this.panel1.Left, this.panel1.Top + 210)},<br />
new byte[] {(byte)PathPointType.Start,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Bezier,<br />
(byte)PathPointType.Line});<br />
<br />
Brush tBrush = new TextureBrush(background);<br />
<br />
temp.FillRectangle(new LinearGradientBrush(<br />
new Point(0, 0), new Point(this.Right - this.Left, 0), Color.SlateGray, Color.WhiteSmoke), this.ClientRectangle);<br />
<br />
temp.FillPath(tBrush, texturePath);<br />
temp.DrawPath(new Pen(<br />
new LinearGradientBrush(<br />
new Point(30, 30), new Point(this.Right - this.Left, this.Bottom - this.Top), Color.WhiteSmoke, Color.SlateGray), 3.5F), texturePath);<br />
temp.FillPath(new LinearGradientBrush(<br />
new Point(50, this.panel1.Top), new Point(this.panel1.Left, this.panel1.Top), Color.WhiteSmoke, Color.CadetBlue), navButtonsPath);<br />
temp.DrawPath(Pens.Black, navButtonsPath);<br />
<br />
graphics.DrawImage(screen, ClientRectangle);<br />
<br />
temp.Dispose();<br />
navButtonsPath.Dispose();<br />
texturePath.Dispose();<br />
screen.Dispose();<br />
}
any help on resolving these issues is appreciated.
|
|
|
|
|
Good to see that you're disposing your objects when done with them!
One thing you should take into account is the PaintEventArgs.ClipRectangle . This is the region that needs to be repainted. It may add some additional logic to your code, but if done decently should improve your performance. Also, cache what you can. If you use a particular brush you've created over and over again, store it in a field instead of creating it each time.
Also, enable double-bufferring if you haven't already to avoid flicker. The easiest way is to call the following in your constructor:
SetStyle(
ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer |
ControlStyles.UserPaint,
true); See the documentation for the Control.SetStyle in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for the quick response Heath...
I've got my app running at around 19M...
Funny thing if I minimize the window then restore the app uses around 5M consistently. Is there an explanation for this?
|
|
|
|
|
You'd better explain yourself a little more, or I'm afraid you won't get a useful answer. What's the situation? You already know how to get substrings, so can you use that method to get your substrings, and use the method you use for getting chars to get chars??? Is it not okay for you (from a performance perspective) to get one-length substrings?
Regards,
Jeff Varszegi
|
|
|
|
|
I'm not sure if i totally understand your question. You begin by asking if it is possible to split a string into substrings and chars. You then proceed by saying that you understand how to do this.
Here's an example, hopefully it will help:
string myString = "this is an example string";<br />
<br />
string mySub = myString.Substring(startIndex, length);
<br />
char myChar = myString[index];
If this doesn't answer your question, maybe try reposting so it's a little more clear.
|
|
|
|
|
Or simply "asdf".ToCharArray() (see the String.ToCharArray method documentation in the .NET Framework SDK). You can also enumerate a String by its chars. If you want to enumerate Unicode code points, see the TextInfo documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hey guys, can any1 please tell me wtf is wrong with the following code :
private void panelRightView_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Graphics oGfx = this.panelRightView.CreateGraphics();
System.Drawing.Rectangle rect = this.picTitleBar.Bounds;
oGfx.DrawLine(_penLine, rect.Right, rect.Bottom, this.panelRightView.ClientSize.Width - rect.Right, rect.Bottom);
}
The scenario is like this: I've two panels on my Windows form panelLeftView (LEFT docking) and panelRightView (FILL docking). In my right panel's PAINT event handler, I need to draw a f@#king line. The line draws ok, works exactly as I want, it expands when I increase the width of the form, but the problem is that this code doesn't work if I decrease the width of the form . The line previously drawn is not cleared when i reduce the form width. Can any .Net guru (especially of C#) tell me why is this happening? Am I doing something wrong ? Or is that problem occuring only to remind me that I'm working on Microsoft's technology where nothing seems to work as expected ???
Please Help.
Thanks
Gurmeet S. Kochar If you believe in God, it's because of the Devil
My CodeProject Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
When resizing the form , you NEED to redraw the control, otherwise it will only display what is in the video memory. My terminology is probably not 100% accurate, but all you really need to know is that you need to refresh your form, and it will work.
just do:
this.refresh();
|
|
|
|
|
|
BTW, I'm issuing this.panelRightView.CreateGraphics() instead of e.Graphics because in the latter case, the line only draw once and then doesn't expand at all when form's width is increased. I dunno the reason but ....
Gurmeet S. Kochar If you believe in God, it's because of the Devil
My CodeProject Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
You need to force the control to refresh when resized and DO NOT create a new Graphics object in the Paint event handler. Besides, even if you do, you must call Graphics.Dispose on it or you're going to find your memory consumption increasing and performance decreasing.
To force your control to repaint itself when it resizes, you can do this a number of ways. The easiest is just to call SetStyle(ControlStyles.ResizeRedraw, true); in your constructor. You could also set the protected ResizeRedraw property to true in your constructor. These result in the same effect.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Besides, even if you do, you must call Graphics.Dispose on it or you're going to find your memory consumption increasing and performance decreasing
Hey, what about that Garbage Collection thing?
Heath Stewart wrote:
To force your control to repaint itself when it resizes, you can do this a number of ways
Well, I tried using SetStyle but it says
"Cannot access protected member 'System.Windows.Forms.Control.SetStyle(System.Windows.Forms.ControlStyles, bool)' via a qualifier of type 'Panel'; the qualifier must be of type 'FormPackages' (or derived from it)".
Gurmeet S. Kochar If you believe in God, it's because of the Devil
My CodeProject Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
Gurmeet S. Kochar wrote:
Hey, what about that Garbage Collection thing?
The Graphics class - like many other class in the .NET FCL - use native resources (unmanaged) so the GC cannot collect them. Read Programming for Garbage Collection[^] in the .NET Framework SDK to learn more.
Gurmeet S. Kochar wrote:
Well, I tried using SetStyle but it says...
As I mentioned, you should call this in your constructor - the constructor for the control you're writing, which means you must extend the base class you want and add it to your constructor:
public class MyPanel : Panel
{
public MyPanel()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer
| ControlStyles.UserPaint, true);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|