I was reading about the .settings file on msdn and I noticed they give 2 examples of how to set the value of a item in the settings. Now my question is what is the real diffrence between the 2 and when would you use one instead of the other, since to me they seem pretty mutch the same.
To Write and Persist User Settings at Run Time
Access the user setting and assign it a new value, as shown in the following example:
Properties.Settings.Default.myColor = Color.AliceBlue;
If you want to persist changes to user settings between application sessions, call the Save method, as shown in the following code:
Properties.Settings.Default.Save();
The first statement updates the value of the setting in memory. The second statement updates the persisted value in the user.config file on the disk. That second statement is required to get the value back when you restart the program.
It is very, very important to realize that these two statements must be separate and never be written close together in your code. Keeping them close is harakiri-code. Settings tend to implement unsubtle features in your code, making it operate differently. Which isn't always perfectly tested. What you strongly want to avoid is persisting a setting value that subsequently crashes your program.
That's the harakiri angle, if you saved that value then it is highly likely that the program will immediately crash again when the user restarts it. Or in other words, your program will never run correctly again.
The Save() call must be made when you have a reasonable guarantee that nothing bad happened when the new setting value was used. It belongs at the end of your Main() method. Only reached when the program terminated normally.
Related
I'm trying to record how a file changes over time down to the smallest details, which means that reading any changes per file save wouldn't give sufficient data for my use-case, it needs to be per-keystroke.
I just tried out inotify, but it can only notify me on file-save, not file-modification.
I then realized (I'm quite inexperienced with file-system stuff) that this is because text-editors use buffers to store yet-to-happen changes, committing the contents of the buffer on file save (I think, at least).
So, it seems to me that I could
read the buffer of a text-editor (which seems like it would have to be code specific to each particular editor; not viable)
force a save to the file on every keypress (which again seems like it would require editor-specific code)
monitor the keypresses of the user, store my own buffer of them, and then once the file is saved, correlate the keypresses with the diff (this seems way too hard and prone to error)
read the contents of the file on an interval faster than a person is likely the press any keys (this is hacky, and ridiculous)
I can't think of any other ways. It seems that to properly get the behavior I want I'd need to have editing occur within the terminal, or within a web form. I'd love to hear other ideas though, or a potential editor-agnostic solution to this problem. Thank you for your time.
My WPF application checks the data on the clipboard to see if it can work with the data or not. Because I set some buttons to be enabled/disabled based on the data (via an ICommand implementation), this code is called frequently.
The work to determine if my application can work with the data can be non-trivial at times, and thus is causing my application to "hang" randomly. I don't believe I can push this work off to another thread since the WPF runtime is expecting a response quickly.
In order to solve this issue, I thought I would compare the IDataObjects (the current one from the clipboard vs. a cached one from the previous attempt. A straight comparison (and even an object.ReferenceEquals does not return the desired results, so I thought I would try the method Clipboard.IsCurrent. The description sounds like exactly what I want, but when I evaluate the following:
Clipboard.IsCurrent(Clipboard.GetDataObject())
the result is false. The current workaround is to compare the data formats on the IDataObject, but that's not a good answer since my application can handle some files from the file system, but not all. So even though the formats are identical, the result on whether my application can handle the data may not always be the same.
Unfortunately, IsCurrent does not work in conjunction with GetDataObject. MSDN's description of OleIsCurrentClipboard (which IsCurrent uses internally) is quite explicit about this:
OleIsCurrentClipboard only works for the data object used in the OleSetClipboard function. It cannot be called by the consumer of the data object to determine if the object that was on the clipboard at the previous OleGetClipboard call is still on the clipboard.
A workaround could be to subscribe to clipboard updates (see e.g.
Clipboard event C#) and evaluate the data only when it changes, potentially in a background thread.
I am involved in using the C API to interact with Lotus Notes and Lotus Domino. I'm running into issues when reading existing Notes out of an NSF. Specifically, reading TYPE_OBJECT fields and even more specifically, $FILE fields (though I'm sure all TYPE_OBJECT fields would fail if I had any others).
I'm using NSFItemInfo to get the summary data on the $FILE field (so I don't need the saved file, I need information about it such as its size, name, etc...).
If I create the Note in memory, Commit it, then read the $FILE field, everything works. If I change my unit test to read an existing Note (instead of creating it in memory), Lotus PANICS with an Invalid Handle Lookup message.
So I'm left feeling like there is something different about loading those fields when I create a Note from scratch Vs opening one already created. Even reading in an already created Note that my own code created gives me the same error, so I think I'm creating the Notes correctly.
I've explored the NSFNoteOpenExt's flags options and have attempted to open the Note with every possible flag described in OPEN_xxx and I always get the panics except when I open the Note with OPEN_ABSTRACT or OPEN_NOOBJECTS. The reason those don't error though, is because they open the Note without the $FILE fields at all, so when I see if the field exists I get a false and the code to read in TYPE_OBJECT fields is never executed.
Any ideas what I'm missing?
I'd provide code, but I'm actually using .NET interop to accomplish all this, and the code is spread across multiple files, etc.... If you have any questions please ask and I'll provide as much detail as I can.
Craig
I figured out the issue. It came from the fact that when using interop in C#, you can't call C macros. OSLockBlock is defined as a macro to another macro to a function. Essentially, it locks the BlockId.Pool pointer, then increments the pointer by BlockId.BlockHandle. I was mis-interpreting that macro logic to be first increment BlockId.Pool by BlockId.BlockHandle, then lock.
Essentially:
Lock(BlockId.Pool)+BlockId.BlockHandle Vs Lock(BlockId.Pool+BlockId.BlockHandle)
It's interesting that the latter would work when creating a new note with new attachments. I finally figured that out as well, BlockId.BlockHandle was always zero when doing that. So that's why that always worked.
No, not another question that asks, "How can I make my messages flow like on Foursquare???"
What I want to know is, how they are getting their messages in the right order and timeframe.
Here's my situation. I have a proc that can get messages for a given day, and then return the selected result set to the web and have on the front end, my code show them and slide new ones on top. However, these "new" ones, aren't new ones, they are just the ones in the set that didn't initially fit on the page, although they "look new". Now what happens when I get to the end, and the set is empty finally...I make another call right?
Well this call is going to get, yes some ones they didn't see, but also all the ones they already saw.
What's a work around for this?
Thanks.
If you only want to show messages once, then persist the Id of the last message and use that as input into the proc on the second call, basically asking for any messages that came in since the last call.
re: Foursquare, I assume you are referring to the "recent activity" on their main page. They seem to call for 30 activities, then just cycle through them showing 11 at a time. They loop through a static list of 30. No second call that I can see.
I'm drawing a blank, or as some would say, having a senior moment. I know there’s a formal definition and a name for the concept where a db operation (stored procedure) that runs in a database will yield the same results if run repeatedly.
It's something in the genre of the Mathematician’s reflexive, symmetric, transitive, etc.
Do you mean "deterministic" - as in will always return the same result if called with the same input?
Or maybe "idempotent", which also means that calling the function again will have no further effect on the database.
IT's called idempotent
I think what you're looking for is Idempotent. Idempotence is a property that can apply to any sort of operation (not just databases). It means that doing the operation any number of times more than once is equivalent to doing it once. I.e. every subsequent operation after the first leaves the state unchanged.
For example, the play button on most DVD remotes is idempotent while playing a video because no matter how many times you push it, it keeps playing. However a power button on your remote is usually not idempotent, because it toggles the machine on and off each time. Idempotence is a nice property because you don't always have to know what state a system is in before engaging an operation to try to produce a given state.
Or perhaps deterministic.
I'm pretty sure you're thinking of the work "Deterministic". A function is deterministic if it returns the same answer for the same inputs all the time. A function is nondeterministic if it can return different answers for the same input.