|
Hi all,
I am developing a Windows Service. This Service connects to a database and on every timer_tick retrieves new records from a database. The ID of the last record retrieved is being saved to the app.config file using the code below:
private void UpdateConfigFile(Int32 lastIndex)<br />
{<br />
Properties.Settings.Default.LastRecordId = lastIndex.ToString();<br />
Properties.Settings.Default.Save();<br />
}
The service works fine and on every timer_tick it picks up only the new records from the database, but if I open the <projectname>.exe.conifg OR <projectname>.vshost.exe.config the LastRecordId value is always 0. It seems like it is storing and reading the config file from memory or something.
Any help would be greatly appreciated
modified 1-Oct-21 21:01pm.
|
|
|
|
|
from memory the config file is a read only document for use in the program so no changes are stored to it. Plus if you change it outside the program while the program is running you need to restart the program for the new readings to take place.
You could save the value to another file that is pointed to by the config file.
|
|
|
|
|
So it makes more sense not to use the .config file in the first place for settings as these, and opt for a normal text file.
Correct?
modified 1-Oct-21 21:01pm.
|
|
|
|
|
No the config file is used for settings that apply to the application for ti's life time. Ie if you only want it to connect to a specific database or which error log source to write to.
For user settings it is not recommended I use it for some settings and point to other files from it.
google and you get some interesting results.
|
|
|
|
|
Ok thanks for the info. Will save the settings in a seperate text file then.
Cheers
modified 1-Oct-21 21:01pm.
|
|
|
|
|
IMO, this is bad design. The app.config file is not meant for that purpose.
You may want to save the last record retrieved somewhere else. Maybe in the database itself, in another table. This would especially work well if you are using a stored procedure to retrieve the records.
Another solution would be to add a flag to the table where you retrieve the records to mark those who have been read.
|
|
|
|
|
It's not storing the value in the app.config file.
The settings object that you have added in visual studio automatically generates a bunch of code that uses the System.Configuration stuff.
Settings that you have chosen to be "Application" settings are stored in the app.config file, and cannot be modified in code. Settings that you choose to be "User" settings have their default value placed in the app.config file, but when you save a change to the value, the save is made to a config file stored in the current users local settings directory. ("C:\documents and settings\username\local settings\apps\appname\appversion\...." I think)
At runtime, when you request a value, the CLR first looks in the c:\docs & settings\... location to load a value from there. If there isn't anything there, it then goes to the app.config file, and finally, if there is nothing there, it uses a default value that is hard coded into the app.
This is why your app.config file always says 0. This is just the default value that is used when no user specific value exists.
Simon
|
|
|
|
|
Hi All
I'm new to C#, and i was wondering if something was possible. I have a switch statement where i want several criteria to lead to 1 bit of code, and another to lead to another etc.
Is there an easy way of doing this? or will I have to code write the same code out for each criteria?
Please help... Thanks...
oooo, the Jedi's will feel this one....
|
|
|
|
|
As long as you have nothing in between, you can fall through case statements in C# using:
switch (myItem)
{
case 1:
case 2:
case 4:
DoSomething();
break;
case 3:
case 5:
DoSomethingElse();
break;
default:
DoSomethingElseAltogether();
break;
} As soon as you put something between two of your case conditions, you have to fall back to the normal way of doing things.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
Your a star... Thanks...
oooo, the Jedi's will feel this one....
|
|
|
|
|
Hugo Monkey wrote: 1 bit of code, and another to lead to another etc
Put each 'bit' of code in a separate method and call the required method from the relavent case.
[Edit] Sorry, misunderstood the post slightly
Hugo Monkey wrote: several criteria
Use fallthrough as Pete suggested.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
The simplest way is to put your "bits of code" as functions
switch( blah )
{
case 0:
FunctionA();
break;
case 1:
FunctionA();
break;
case 2:
FunctionB();
break;
}
etc
|
|
|
|
|
Hi
Can some one tell what is the right algorithm to use Encrypt any files in C# and that need to be decrypted in Java by using key ? Show me some samples if you have..
Thanks
|
|
|
|
|
As long as you are using algorithms that both platforms understand, then there shouldn't be a problem. You could use SHA-1 for example.
Regards
Sebastian
|
|
|
|
|
you can try bouncycastle[^]
you can use any algorithms you like
dhaim
ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro"
in the front line gave a lead, in the middle line build goodwill, in the behind give power support
|
|
|
|
|
Hi,
here is code line
Process.Start(@"C:\test.exe", @"C:\Temp Dir\sequence.seq");
the thing is the second string, because it has space in the directory name
the test.exe failes to open the file
i've changed the location to : C:\sequence.seq and it works fine
so it's not the file problem
how can i handle the sapce in the string??
thanks
Have Fun
Never forget it
|
|
|
|
|
Wrap it in quotes;
Process.Start(@"C:\test.exe", "\"C:\\Temp Dir\\sequence.seq\"");
Enjoy
I are troll
|
|
|
|
|
|
how can i get out from the outer for in a for-for-if situation.
For example
for...
{
for...
{
if...
{
break;
}
}
}
The break only breaks from the inner for, i want it to break from the outer for too.
Could you help.
|
|
|
|
|
you have to break it twice or use goto
for (int a = 0; a < 5; a++)
{
MessageBox.Show(a.ToString());
goto LoopBroke;
}
LoopBroke:
MessageBox.Show("Loop completed");
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Continue[^] also only breaks a single loop. You could add a flag called 'done', check this in the outer loop, and do a second break if it's true. Or, you use a goto[^].
Disclaimer: the goto suggestion should not be taken seriously
I are troll
|
|
|
|
|
You can't (See the reply from XMen)
You could consider restructuring the loop to use a while loop instead. You might find if you structure it differently that you don't need the break.
Simon
|
|
|
|
|
I suggest you go for the goto suggestion. While goto is discouraged, I find it helpful sometimes. It may even simplify the code more than what another structure would do. In this case, IMHO, it will (depending on the context too). A go to will not cost you an extra boolean value and saves an extra if statement.
Eslam Afifi
|
|
|
|
|
Your question shows that you have a misunderstanding of what a for loop actually does. I cringe whenever I see people use break statements inside for loops because it shows they've just gone for convenience without actually considering what they are trying to do.
A for loop is used to iterate a predictable and set number of times; that's what it's for (pardon the pun). If you need to iterate an indeterminate number of times, then you should consider using a boolean based loop structure, i.e. while ... do or do ... while instead (and yes - I know that a for loop is boolean based in that the exit condition is satisfied when you reach the to value in the count). Then, your logic makes more sense because you've based your exit on the condition you're testing.
Please, consider redoing your looping mechanism to a one that's a better fit. Whenever I see people recommending break or goto statements, I know that they are being lazy or have given no thought to what the proper use of the loop should be.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|