|
Thanks for your replies. In hindsight, I see that I could have answered this question myself had I put a bit more thought into it. Anyway, thanks again. 
|
|
|
|
|
Hi,
I created a datagrid, bonding with a datatable, with some columns editable. If edit the fields in one row, and cursor stays in the same row,RowState is still "Unchanged", although the datatable has the new value now. RowState will be "Modified" only when I move the cursor to another row. But I want to save my changes to database without moving the cursors to other rows. How should I do it?
BTW, I use :
"if (r.RowState != DataRowState.Unchanged && r.RowState != DataRowState.Deleted)" to judge whether there are changes need to be saved. I don't want to remove this condition because it will cause a lot of unnecessary updates.
Thanks.
|
|
|
|
|
Get the CurrencyManager for the DataGrid and call EndCurrentEdit like so:
CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember];
if (cm != null)
cm.EndCurrentEdit();
Also, use DataSet.GetChanges or DataTable.GetChanges and get the Count of rows for the tables. This is a better way of determining changes plus gives you a DataSet of just the changes so that you can pass that to your methods which update the data source (i.e., database). This will also be more efficient if you need to send this DataSet across application boundaries since it won't (potentially) require as much bandwidth since it would have fewer rows.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks a lot! CurrencyManager works fine for my case.
Appreciate for your response!
|
|
|
|
|
Application Type: C# Windows Application
This application generates multiple reports in batch. For each report requested in the batch, main process spawn threads. Each thread connects to database gets DataSet and Invoke a method to attach ReportDocument with the CrystalReportViewer.
Now after threads complete execution, result is multiple reports. Even after I close all reports, I don't see the Mem Usage coming down. This looks like to be an issue with memory taken during the execution of threads.
Can somebody suggest what should be done for fast memory recovery
Thanks
Ruchi
|
|
|
|
|
|
Search your code for the instanciation of objects of classes that implement the IDisposable interface.
Most of this classes allocate unmanaged resources that are freed by calling their Dispose method, but not when they are collected by the GC.
I learned about that recently by reading a posting from Heath. Here is the linke towards our small conversation: http://www.codeproject.com/script/comments/forums.asp?msg=798736&forumid=1649#xx798384xx
|
|
|
|
|
Troschi wrote:
Most of this classes allocate unmanaged resources that are freed by calling their Dispose method, but not when they are collected by the GC.
If they're not freed at all, that's a bug in the class. Classes that allocate unmanaged resources should implement a finalizer (using the 'destructor' syntax in C#, ~ClassName ) which frees the resources.
Finalizers have a few problems in the current releases of the Framework. Firstly, the memory is only released on the second collection that hits this object. The first GC detects there are no references to this object and that it has a finalizer, so it puts the object on a finalization queue. A thread that's reserved only for calling finalizers reads this queue and calls the finalizer for each object. Once the finalizer has run, it removes the reference. The next time the GC runs for the appropriate generation (the object is considered to have survived the original collection and is promoted to the older generation) the memory will then be freed.
If you're writing your own classes, you should call GC.SuppressFinalize in your Dispose method to indicate that the object no longer requires finalization. This saves the object surviving unnecessarily.
You should still call Dispose (or use a using block) to avoid the unnecessary memory pressure caused by the implementation of finalization. Consider the finalizer to be a back-stop against failing to call Dispose .
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
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.
|
|
|
|
|