|
Thanx Willem, that is short and just what it should do )
|
|
|
|
|
Something that you have to consider, though: Using a separate thread to save the data means that you have to make sure that the operations on the data is thread safe, e.g. that you don't save the data in the middle of an update, and don't update in the middle of a save.
---
b { font-weight: normal; }
|
|
|
|
|
Yes, got that covered. Making a copy in memory of what i want to save first.
Thanks.
|
|
|
|
|
Any tips on repeating the thread eg. every 10 minutes?
|
|
|
|
|
Yep, add a while(true) construction around the code in the autoSave method
WM.
What about weapons of mass-construction?
|
|
|
|
|
You can easily solve that problem by locking the data you are saving:
private boolean enableAutoSave = true;
private Thread autoSaveThread = new Thread(new ThreadStart(autoSave));
autoSaveThread.start();
void autoSave() {
while(enableAutoSave) {
Thread.Sleep(10 * 3600000);
lock(data) {
save(data);
}
}
}
WM.
What about weapons of mass-construction?
|
|
|
|
|
Thanks Willem !
Works perfect !
I assumed that a While there would 'hog' the system/application, but no problem there
|
|
|
|
|
pxp wrote: Making a copy in memory of what i want to save first.
That doesn't solve the problem, it just somewhat decreases the risk for data corruption. The only difference between saving the data and copying the data is the amount of time it takes. You still have to lock the data while copying it.
---
b { font-weight: normal; }
|
|
|
|
|
I get my data from a class collection and print them to a textfile.
I should lock the class-collection before i save the data,...ok,..not thought about that...is that correct?
|
|
|
|
|
Yes, that would work.
Note, though, that if the main thread is trying to access the data while it's locked, it will freeze up until the save is complete.
---
b { font-weight: normal; }
|
|
|
|
|
Hello even i wanna save my controls value on the page every 30 sec auto save.So i just tried the code which you mentioned
LoadData()
{
Thread thd = new Thread(new ThreadStart(autoSave));
thd.Start();
}
private void autoSave()
{
Response.Write(System.DateTime.Now);
Thread.Sleep(10000);
LoadData();
//Wait 20 seconds //TODO: Handle autosave functionality
}
but the second time it throws error saying response in not available in the context ??
|
|
|
|
|
Hi all,
i have some trouble with XML file reading.
My logic:
<br />
XmlWriter myXmlWriter = new XmlTextWriter(_filename, System.Text.Encoding.UTF8);<br />
myXmlWriter.WriteElementString( "Version", "example string" );<br />
...etc...<br />
<br />
XmlDocument myXmlDocument = XmlDocument();<br />
myXmlDocument.Load(_filename);<br />
...<br />
string strVersion = myXmlNode["Version"].InnerText;<br />
When opening a xml file i get the following error: "There is no Unicode byte order mark. Cannot switch to Unicode."
What i would like to achieve is a simple XML save/load for some values i wanna retrieve at runtime.
My suggestion without the use of Encoding:
<br />
TextWriter tw = new StreamWriter(_filename);<br />
XmlWriter myXmlWriter = new XmlTextWriter(tw);<br />
I could be getting the problem becuase the xml file was manually edited at one time using Notepad.
My question(s):
Can (or may) i skip the "System.Text.Encoding" ?
And if so, what are the downsides of it ?
Thanks in advance,
Jan
|
|
|
|
|
You can skip the encoding in the call that creates the stream, but that doesn't mean that it's not using any encoding. It will be using the default encoding, which is UTF-8.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks Guffa.
I had a problem with: "There is no Unicode byte order mark. Cannot switch to Unicode." but don't know what tha cause of it is...
My goal is to have a 'bulletproof' xml reader/writer.
|
|
|
|
|
Hi, im looking at some Java code and im assuming that the synchronized keyword is pretty similar to the lock keyword in C#? Anyone able to confirm that?
In addition I think this code is replicating some of the .NET System.Threading.Monitor class, but again I am unsure. How would I replicate this code with the use of lock keyword and Monitor class?
This is some example Java of what im looking at. What is the equiv of the .notify() method below in the .NET Monitor Class? Im pretty sure .wait() is erm... Wait()
private Object unsafeLoaderMonitor = new Object();<br />
public void DoSomething()<br />
{<br />
synchronized (unsafeLoaderMonitor) <br />
{<br />
unsafeLoaderMonitor.notify();<br />
}<br />
}<br />
<br />
public void DoSomethingElse()<br />
{<br />
synchronised(unsafeLoaderMonitor)<br />
{<br />
unsafeLoadMonitor.Wait(100000);<br />
}<br />
}
|
|
|
|
|
I do this to implement a synchronized method:
void MySychronizedMethod()
{
Monitor.Enter (this);
try {
}
...
finally {
Monitor.Exit (this);
}
}
I believe this is equivalent to:
void MySychronizedMethod()
{
lock (this) {
}
}
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Note that you can make a method synchronous by decorating the method with the Synchronized method implemetation attribute.
using System.Runteim.CompilerServices;
...
[MethodImpl(MethodImplOptions.Synchronized)]
void MySynchronizedMethod()
{
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|
|
as the subject says i try to use the axiom engine and wated to try out this tutorial:
http://www.cs.usask.ca/~djj734/AxiomTuts/Tut1/AxiomTut1.html
it looked very easy and i think i ve understood it.
but when i try to run the .exe i get this exception:
Das Element wurde bereits hinzugefügt. Schlüssel im Wörterbuch: "egyptrockyfull
.jpg" Hinzuzufügender Schlüssel: "egyptrockyfull.jpg"
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add
)
at System.Collections.Hashtable.Add(Object key, Object value)
at Axiom.Core.ResourceManager.AddCommonArchive(String name, String type)
at Axiom.Utility.TechDemo.SetupResources()
at Axiom.Utility.TechDemo.Setup()
at Axiom.Utility.TechDemo.Start()
at AxiomTut1.Tut1.Main() in e:\downloads\visual studio projects\axiomtut1\tut
1.cs:line 77
-->
Das Element wurde bereits hinzugefügt. Schlüssel im Wörterbuch: "egyptrockyfull
.jpg" Hinzuzufügender Schlüssel: "egyptrockyfull.jpg"
<--
means (i try to translate):
the element was already added. key in the dictionary: "egyptrockyfull jpg" key which can be added: "egyptrockyfull.jpg"
....
i searched for "egyptrocky.jpg" and found it in the media directory and in the zipfile fresnel.zip
...
but if i delete one of them (or remove fresnel.zip from the engineconfig.xml) i get an other exeption
is there anybody who could help me plz
|
|
|
|
|
Did you happen to read the dsclaimer at the bottom of the page you supplied? Ask the person who wrote the tutorial! It's extremely unlikely that anyone here has gone through what your doing.
Disclaimer: I made my best attempt at a tutorial, but by no means know the ins and outs of everything Axiom. I hope it is all correct, and I hope it works well for you but if something is incorrect or does not work, please let me know so that it can be fixed. <br />
<br />
The address you can send a note to is meta@the-void.ca<br />
<br />
<br />
<br />
RageInTheMachine9532<font size="-1"><br />
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome</font>
|
|
|
|
|
Hi!
I'm testing data transfer to a web service (using VS.NET 2k3 and c#) and I've observed the following:
- passing and returning any simple type object works fine.
- passing and returning any array of simple type objects works fine too.
BUT
- passing and returning any array of objects of this class:
<br />
public class Type1 <br />
{<br />
protected int x;<br />
protected int y;<br />
<br />
public int X<br />
{<br />
get <br />
{<br />
return x;<br />
}<br />
}<br />
<br />
public int Y<br />
{<br />
get <br />
{<br />
return y;<br />
}<br />
}<br />
<br />
public Type1(int x,int y)<br />
{<br />
this.x = x;<br />
this.y = y;<br />
}<br />
}<br />
throws an exception.
My question is how to pass this correctly. Maybe using XML, but how?? I'm a bit newbie on this.
Thanks to anyone.
|
|
|
|
|
Please don't cross post.
---
b { font-weight: normal; }
|
|
|
|
|
what to do you mean with cross post? Posting on two boards? Sorry, I didn't know where to ask.
|
|
|
|
|
Hi all,
How can i create a serial number that will let the program know until what date it can be used?
importnant: i need the serial number to be short, somthing like this will be fine:
xxxx-xxxx-xxxx-xxxx-xxxx-xxxx
much longer than that would be bad.
Thanks alot,
Ran.;P
R.Z
|
|
|
|
|
|
Or try to deploy your project and there u can add a serial number or cd-key it aguation its output must be divisable by 7
|
|
|
|