|
Hi,
Are you intending to save settings that are made during the execution of the programme? If so you should be using "userSettings". I think the "applicationSettings" section is intended to be read only and configured at design time or by manually editing the appname.exe.config file but I may be wrong on this.
The default values for user settings are stored in appname.exe.config but runtime changes are saved to user.config which resides deep down in a user's Local Settings directory.
The code to read and write user settings can be as simple as this.
String greeting;
private void ReadSettings() {
greeting = Properties.Settings.Default.hello;
}
private void WriteSettings() {
Properties.Settings.Default.hello = greeting;
Properties.Settings.Default.Save();
}
AlanN
|
|
|
|
|
Hello everyone,
If I am using the ReaderWriterLock class, in the following 3 situations, except performance degrade, are there any functional issues? E.g. deadlock?
1. Acquire a specific write/read lock, and then acquire the write/read lock again, but release the write/read lock twice;
2. Acquire a specific read lock, and then acquire the write lock for the same object, and release in reverse order write lock, then read lock;
3. Acquire a specific write lock, and then acquire the read lock for the same object, and release in reverse order read lock, then write lock.
thanks in advance,
George
|
|
|
|
|
Readers can acquire the lock only if there are no writer threads. You did not specify if you are using AcquireReaderLock or AcquireWriterLock. Anyway if you acquire the lock (reader or writer) and you try to call the Release method twice you'll get an exception.
These operations are exclusive (you have a lock for one or more readers or you have a lock for only one single writer). The AcquireReaderLock, AcquireWriterLock methods supports a timeout value, if the timeout expires an exception is thrown.
From MSDN:
"If the current thread already has the writer lock, no reader lock is acquired. Instead, the lock count on the writer lock is incremented. This prevents a thread from blocking on its own writer lock. The result is exactly the same as calling AcquireWriterLock, and an additional call to ReleaseWriterLock is required when releasing the writer lock."
"AcquireReaderLock supports recursive reader-lock requests. That is, a thread can call AcquireReaderLock multiple times, which increments the lock count each time. You must call ReleaseReaderLock once for each time you call AcquireReaderLock. Alternatively, you can call ReleaseLock to reduce the lock count to zero immediately."
|
|
|
|
|
Thanks Zoltan,
I read the document again. Two more issues
1.
When a thread acquires a read lock, and then upgrade to write lock, the thread is not ensured to continue to hold the lock and proceed executuion, since it will be appended to the end of the write lock queue, and in this scenario a thread which waits for read lock will be awaked, and the awaked thread will hold read lock? Right?
2.
So, if I want a thread to proceed execution and hold lock all the time, I need to let it own write lock at first, other than upgrade?
regards,
George
|
|
|
|
|
When a read lock is upgraded, the write lock request will be placed in the end of queue. So all the read/write locks will be processed before this one gets access.
George_George wrote: So, if I want a thread to proceed execution and hold lock all the time, I need to let it own write lock at first, other than upgrade?
If you want to hold the lock all the time, you should not use ReaderWriterLock class. It is used to support single writers and multiple readers. BTW, why you want to hold the lock all the time ?
Also if you are on .NET 3.5, use ReaderWriterLockSlim which is more efficient than ReaderWriterLock . Many people has reported several drawbacks for ReaderWriterLock .
modified on Thursday, April 17, 2008 1:52 AM
|
|
|
|
|
N a v a n e e t h wrote: It is used to support single readers and multiple writers.
It's the other way around: single writer multiple readers.
|
|
|
|
|
OOPS, it's a typing mistake. Thanks for pointing that.
|
|
|
|
|
Thanks N a v a n e e t h,
Sorry I have to use .NET 2.0 in current application.
My purpose is, I want the thread which holds the read lock, continue to hold the write lock after lock upgrade. I think ReaderWriterLock class is not suitable, since when we upgrade the read lock, the current thread will be appended to the last of the writer queue, and reader will proceed to acquire the lock, and then read will proceed to run, right?
regards,
George
|
|
|
|
|
George_George wrote: then read will proceed to run, right?
Yes. If there is no pending read requests, immediately write lock will be granted. ReaderWriterLock class alternates between read and write lock.
George_George wrote: I want the thread which holds the read lock, continue to hold the write lock after lock upgrade
I think you should go with a manual locking using the lock keyword. It would be tough to implement, but you are not limited to something like ReaderWriter.
|
|
|
|
|
Thanks N a v a n e e t h,
The only two cases when exception will be thrown in all operations of ReaderWriterLock are, right?
http://msdn2.microsoft.com/en-us/library/system.threading.readerwriterlock(VS.80).aspx[^]
1.
If the time-out interval expires and the lock request has not been granted, the method returns control to the calling thread by throwing an ApplicationException. A thread can catch this exception and determine what action to take next.
2.
If you specify a TimeSpan that represents a negative number of milliseconds other than -1, ArgumentOutOfRangeException is thrown.
regards,
George
|
|
|
|
|
The window consists of 5 buttons. When the window loads, it checks the .key file whether the buttons to be visible. The form start position is defaulted to center screen.
Let's take the scenario:
3 buttons would not be visible,
the window shrinks by 169 (pixels?) horizontally.
This has resulted that the form window to be off center on the screen.
Now the question is:
How the heck do I refresh its position after the form size has changed?
|
|
|
|
|
Oh never mind... I've got it.
Gotta do this BEFORE the form becomes visible (loaded) so it would be centered as it should.
|
|
|
|
|
Use System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height/Width and do the math.
like (screen width/2) - (window.width/2) and do the same for the vertical dimension...
Hey, thanks for sharing your answer when you found it mate!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hey guys, I am writing a windows c# services that monitors servers and determines if the server is up or down based on whether or not it checks in. If one of the servers doesn't check in, the service needs to place a call to the tech on duty. What would I need to use to make a call in c#?
Thanks in advance,
Travis
|
|
|
|
|
tcombs07 wrote: What would I need to use to make a call in c#?
You can use TAPI.
|
|
|
|
|
I have doubt from ur TAPI?
how can u use the normal .net framework application TAPI?
|
|
|
|
|
You could buy a gprs wavecom modem. Wavecom Fastrack Supreme StarterKit[^]
Stick yourself a mobile SIM card in it, and then send out SMS messages to whoever the tech guy on call.
Then it would just be a case of using: "System.IO.Ports.SerialPort" to write the sms command to it.
Failing that you could just buy this activesms toolkit: http://www.activexperts.com/activsms/[^]. The instruction on how to send a sms message using c# look easy enough. http://www.activexperts.com/xmstoolkit/howto/mm1/vcnet/[^]
This will allow you to send/recieve sms messages to your wavecom, so you could get your tech guy to reply to the sms message to acknowledge he has recieved it.
|
|
|
|
|
If the tech uses a cell phone and the server has internet access, you can just send an sms message or email. If that's the case, then check out the API's that the service provider has.
|
|
|
|
|
tcombs07 wrote: How to make a phone call?
First, pick up the phone....
(sorry, couldn't resist)
|
|
|
|
|
lol
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Yes
i have mananged dll for that
|
|
|
|
|
I would be very interested in getting that dll you have to do this? would that be at all possible?
Thanks,
Travis
|
|
|
|
|
I'm also would like give free,but it's have some probs.
if want to any information email me to vrrave@yahoo.com
|
|
|
|
|
Hiya all,
I was wondering if someone could tell me whether i can define the maximum number of rows for a ListView. I am using the ListView in detail mode and would like a maximum of 1000 rows. When i insert the 1001 row i would like the first row inserted to be deleted.
thanks in advance
|
|
|
|
|
ahh i think i got it!
When i add a new row to the list control i have also added some code that checks the number of rows currently in the list. If its = to a 1000 then i delete the 1000th row!
Code looks something similar to this:
if (UpdateList.Items.Count > 10)
UpdateList.Items.RemoveAt(10);
|
|
|
|