|
Hi,
let me summarize that for you: you have a collection of objects (e,g, tab pages on a form), and these objects may or may not contain "dirty data" i.e. data that still needs to be saved, how to make sure it all gets saved?
This is what I do:
1. I give each object a bool dirty flag, which starts at false; gets set true whenever I change something to the object; and gets set false again when the object's content is either read from or written to permanent storage, such as a disk.
2. when I want to close the app, or close all the objects of the GUI, I enumerate the collection of objects, and for each dirty object, I ask the object to persist itself in any way fit; it is the object itself that either knows how to do that (because it holds the file path) or has to ask the user (because it does not know a file path yet).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Ahh... That was so perfect it was almost peotic. Your answers are always spot on. Thanks you very much Luc
Jase
|
|
|
|
|
Just adding to Luc's reply, adding a "Do this for all modified files" checkbox will be a nice option to have. Just imagine 30 open documents and all are 'dirty' when the user chooses exit. Also, a "Save all" button on your toolbar would look cool.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thank you Rajesh That's a great idea, I'll definately do that. Thank you.
|
|
|
|
|
Rajesh R Subramanian wrote: Just imagine 30 open documents and all are 'dirty' when the user chooses exit.
I wouldn't advise you to get yourself into such situation. One medium-sized alpha particle could ruin your day.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
The only thing I add to that is a "changed" event thrown upward - that way the parent can give a visual indication in the tab or whatever (just like VS does with the "*" next to the file name) - and does not have to iterate though all tabs to find any dirty data on closing.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
No problem, as long as the DirtyChanged event only fires on an actual change of bool dirty. Otherwise every keystroke would set of a whole chain of mostly unnecessary actions.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hmmm... It looks like I have alot to think about. This is gonna be fun
|
|
|
|
|
From what I can gather you have a number of tab pages that contain basically the same controls but can contain different data. when you close all tabs then you want to check certain data and prompt for a save if need be. Is that correct?
What I would do in this instance is create a custom control that will basically be the only control on each of the tab pages. This control will have all your other controls however you choose to lay them out. This custom control should then have a function called ValidateClose() or something that does your tests and prompt the user or whatever. This can then be called in side the foreach loop of each tab when you are closing them all.
using a switch block is basically the same as if else if logic, so use which ever you prefer.
Hope that makes sense and offers some help
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thanks alot musefan now I have 2 great answers! I'm going to get working on it right away thanks to you guys, and once I'm done, I'll post the code incase somebody else wants to know.
Thanks again musefan and Luc
|
|
|
|
|
hi..
I want to compress below 1kb to store on smart card which has usually less memory (1kb) , please suggest me some c# function ...
The image is for general use.
|
|
|
|
|
Hi,
you have asked similar things before. It wasn't clear then and it isn't clear now: do you need a way to reduce an image to a single block of data less than 1KB? or are you looking for ways to split it in several blocks of data each less than 1KB?
And how large are your images (both in pixels and in KB when stored as JPEG)? and what is on your images: faces, landscapes, something synthetic?
Could you show such an image?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Predicted answer to your questions...
"Yes, That's exactly what I want. Can you give example"
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Of course I have an example ready. It will probably be an icon file if that conforms to the question.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Ah, you are well prepared as always
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
My king-sized toolbox is almost full, and so is my disk.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
If you want a colour image, I think you'll struggle - A 150x150 pixel jpeg photo saved at 1% quality, you get a file that's just a little bit bigger than 1kb. When you view it it's just a random selection of blotches that vaguely resemble the photo, if you stand a few feet away and squint, but its not recognisable as the original image.
For black and white, you can get a black and white dithered 80x80 pixel image as a png saved to less than 1kb. Again, you really can't see any detail, and it's only recognisable if you squint.
It all really depends on what you actually need to do. You might be better off keeping your images in a database, and just storing the db key on your card.
|
|
|
|
|
Save the image as a 40x40 jpeg.
|
|
|
|
|
Hi
i have number of window services running on production server(Window server 2003 dedicated for window services).Everything was running fine from last 6 months but now some services start giving error System.OutOfMemoryException.
I think this issue is due to memory leaks.Now my questions are
(1)For immediate solution restarting of window services is enough or i have to restart the Production server.
(2)How to find the possible cause of memory leak and suggestion for possible causes of memory leak
himanshu
|
|
|
|
|
Hi,
there are many possible causes. Here is one most people aren't aware of:
objects larger than 80KB get allocated on the "large-object-heap", which never gets compacted. The net result is it may fragment after some time, resulting in lots of memory being free yet the heap being unable to offer a chunk of memory large enough to satisfy the latest request.
Here are some candidates for large objects:
- images
- arrays in general
- large strings (TextBox/RichTextBox often is a culprit, as it requires the concatenation of all its text)
- StringBuillders and all kinds of collections since these typically are implemented as arrays as well; such objects get an initial capacity, and when insufficient, their array gets reallocated with twice the size.
Solution: there isn't a perfect solution. Some suggestions:
- avoid large objects as much as possible, don't use (Rich)TextBox for texts exceeding a few hundred lines
- when a StringBuilder or collection will grow large, allocate it with sufficient size right away.
- periodically restart your app (once a month, once a day, depending on how active its object allocation is)
BTW: I know of no readymade way to measure fragmentation; it is easy to measure it in a disruptive way though (I think I'll write a little article on that subject).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Tuesday, July 14, 2009 7:19 AM
|
|
|
|
|
Thanks Luc for sharing your knowledgw with us.
Luc Pattyn wrote: Here are some candidates for large objects:
- images
- arrays in general
- large strings (TextBox/RichTextBox often is a culprit, as it requires the concatenation of all its text)
- StringBuillders and all kinds of collections since these typically are implemented as arrays as well; such objects get an initial capacity, and when insufficient, their array gets reallocated with twice the size.
But possibility of above scenarios are not there in case of my window service. In my case , i am calling a web service which puts the message in the IBM MQ.Exception comes whenever i attemp to call the web service method.
(1)One possible cause for exception might be that the message size is very big ... waiting for your views on that
(2)Also, is it possible to monitor the memory used be window service(something with performance counter or some other way) ???
(3)For immediate solution should i restart my production server or restarting of window service do the trick...
himanshu
|
|
|
|
|
Hi,
(1) I have no idea what the size of those messages would be. 80KB seems rather big for a message?
(2) fragmentation, the topic of my reply, is not caused by the amount of memory currently in use, it is caused by how the number and sizes of memory blocks evolve over time; and AFAIK Microsoft offers nothing to measure it. I know of an easy way to test it, but that test includes actions that fill the memory, i.e. allocate more until it fails. That probably is not what you want in an app, as it only makes sense if you can halt all threads but one, then fill the memory, then clean up again. The net result is you can prove there is fragmentation and how bad the situation is, it does not remedy anything.
(3) Restarting the process that throws the OOM would technically be a solution, no matter what the exact cause of the OOM is; whether it is functionally acceptable is up to you.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks Luc for you reply
Luc Pattyn wrote: 80KB seems rather big for a message
I also think so.
Luc Pattyn wrote: fragmentation, the topic of my reply, is not caused by the amount of memory currently in use, it is caused by how the number and sizes of memory blocks evolve over time
In that case if window service is idle for some time then why not garbage collector comes in picture and free the allocated memory
himanshu
|
|
|
|
|
I see you haven't really understood my point yet: the large-object-heap does not get compacted, i.e. when there are empty holes in the one huge memory block it manages, then the occupied blocks are NOT shifted to create one big empty hole; moving large blocks was considered too expensive. The net result is, you could have 2GB of memory filled with a pattern like this:
80KB in use
90MB free
80KB in use
90MB free
80KB in use
...
80KB in use
90MB free
80KB in use
90MB free
which means less than one percent is in use, and still you can't allocate a single 100MB block.
That is what fragmentation is about; and that is why "memory usage" numbers don't tell you whether the situation exists or not.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Your Service should be logging what method throws the Exception. You should be able to add more log messages like "I'm about to get a list of employees", etc. See if it's always the same action causing the problem (it may not be).
I write a lot of Windows Services, I don't keep a lot of data in the fields, mainly just database connections. Everything else is local to the methods in use so it gets garbage collected.
Review what data you keep in fields and rethink whether or not it needs to be.
|
|
|
|