Synchronous writes to a file

E

Erick Sasse

I have a very simples asp.net app with a simples form and two textboxes.

When the user fills the textbox and post, I save it to a XML file.
I'll have eventually more than one user trying to save at the same
time.
Do I need any protection code for this critical section?

I was looking at lock statement, but I don't think it fits my need.
 
S

Skippy

Erick Sasse said:
Why obvious? Database is not a solution for every problem.

--

IMO a database is the right solution for this problem.

XML is not a solution for every problem either....

The conversation sounded like this:

Erick: "I am having trouble pounding in this screw with a hammer"

Frankie: "Use a screwdriver"

Erick: "No, I want to use a hammer - but it is not working right..."
 
E

Erick Sasse

Frankie said:
Okay, then what do you mean by "protection code"?

Like the lock statement in C#, so that I don't get more than one thread
trying to write the file at the same time.
 
F

Frankie

It's hard to be much help here because you don't say much about what you are
trying to accomplish and why other solutions are not acceptable to you.
What's wrong with the lock statement from your point of view? If we know
what you don't like about it then we might be able to come up with another
solution that doesn't also have the same problem. Because we don't really
know what you're unhappy about we don't know much about our target.

We are really engaged in art as programmers because there are so many ways
to accomplish the same thing. For example, assuming that you cannot or do
not want to lock a file or use a database (for
onlygodknowswhatreasonsatthispoint), you *could* simply update a DataTable
object in your site's Application state. Then you could periodically write
the DataTable's contents as an XML file to disk. Real easy to do this. But
can we recommend it for you? No way! We don't know anything about what
you're actually trying to accomplish and *why* more mainstream approaches
may not be reasonable in your situation.

A few things are relevant here:
-- We can't read your mind.
-- If you don't know where you're going, then any road will take you there.

HTH

-F
 
E

Erick Sasse

Thanks Frankie,

I think my english is not good enough to make you understand what I
want. :)

And I certainly need to study ASP.NET a little bit more before asking
questions.
 
F

Frankie

Your English is fine, and you do not have to be an expert before asking
questions here! Just tell us a bit more about what you want to accomplish,
and what limitations you may have. We can certainly get creative here and
come up with a solution that will meet your needs while working around any
limitations.

Remember - this is art! not science...

-F
 
E

Erick Sasse

Frankie said:
Your English is fine, and you do not have to be an expert before
asking questions here! Just tell us a bit more about what you want to
accomplish, and what limitations you may have. We can certainly get
creative here and come up with a solution that will meet your needs
while working around any limitations.

I'll put the app in production the way it is. If it doesn't work the
way it works while testing, I'll ask again for help.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top