473,473 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: ASP.NET file system operations...should file writes use locks?

On Jun 3, 8:12 am, moo <ntv1...@gmail.comwrote:

<snip>
My question is: do I need that lock?
I seriously doubt that it'll be doing anything useful at the moment.
You're locking on "this", but a new page instance is created for each
request, I believe.
My initial feeling is that since
I'm creating a file name based upon the names entered in the fields (I
should probably sanitize those inputs..aside from regexs looking for A-
Z, any other checking ideas I should do would be welcome), I may
someday have the odd condition where two users are entering
information for the same person and happen to click the button at the
same time, possibly creating a race condition. Is that accurate?
I would suggest creating a file with a temporary filename (e.g.
creating a new GUID and using that) and then modify EmailOverseer so
it can send the attachment *as if* the file had the desired filename.

In fact, does EmailOverseer really need the file to be on disk in the
first place? Any reason you can't use memory directly? (e.g.
MemoryStream)

Jon
Jun 27 '08 #1
2 1238
moo
Good point...I was thinking I needed to instantiate a file object and
then lock on that object, but I tried to get lazy and use the static
method (because a couple of bytes on the stack are all so
important...*smacks self*) without thinking it through.

Thanks for your suggestion, I can probably do that...this is more of a
proof in concept solution, and the dumb and lazy approach is to
automatically generate the report in a file and then attach that file
to the e-mail...if I want to get fancy I may want to generate an XML
so I can e-mail it out in HTML format and have a source for back end
queries later, but that's another topic...

The main gist of the question was, what are some standard patterns/
best known methods for handling file system interactions in ASP.NET?
Do we treat them similarly to multi-threaded console apps, or are
there other considerations we need to account for/simplify things? Any
specific resources would be welcome.

On Jun 3, 1:44 am, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Jun 3, 8:12 am, moo <ntv1...@gmail.comwrote:

<snip>
My question is: do I need that lock?

I seriously doubt that it'll be doing anything useful at the moment.
You're locking on "this", but a new page instance is created for each
request, I believe.
My initial feeling is that since
I'm creating a file name based upon the names entered in the fields (I
should probably sanitize those inputs..aside from regexs looking for A-
Z, any other checking ideas I should do would be welcome), I may
someday have the odd condition where two users are entering
information for the same person and happen to click the button at the
same time, possibly creating a race condition. Is that accurate?

I would suggest creating a file with a temporary filename (e.g.
creating a new GUID and using that) and then modify EmailOverseer so
it can send the attachment *as if* the file had the desired filename.

In fact, does EmailOverseer really need the file to be on disk in the
first place? Any reason you can't use memory directly? (e.g.
MemoryStream)

Jon
Jun 27 '08 #2
moo <nt*****@gmail.comwrote:
Good point...I was thinking I needed to instantiate a file object and
then lock on that object, but I tried to get lazy and use the static
method (because a couple of bytes on the stack are all so
important...*smacks self*) without thinking it through.

Thanks for your suggestion, I can probably do that...this is more of a
proof in concept solution, and the dumb and lazy approach is to
automatically generate the report in a file and then attach that file
to the e-mail...if I want to get fancy I may want to generate an XML
so I can e-mail it out in HTML format and have a source for back end
queries later, but that's another topic...

The main gist of the question was, what are some standard patterns/
best known methods for handling file system interactions in ASP.NET?
Do we treat them similarly to multi-threaded console apps, or are
there other considerations we need to account for/simplify things? Any
specific resources would be welcome.
I haven't heard of any particular rules - I'd just say:

1) Writes should usually be to different files anyway, apart from for
logging (lock in that case)
2) Concurrent reads should be fine (open shared) so long as you don't
have anything else writing
3) Try to avoid it in the first place if possible

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: simon place | last post by:
is the code below meant to produce rubbish?, i had expected an exception. f=file('readme.txt','w') f.write(' ') f.read() ( PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) on win32. ) I got...
1
by: aswinee | last post by:
I am running Microsoft SQL Server 2000 - 8.00.760 Enterprise Edition on Windows 2003 Enterprise Edition (NT 5.2 Build 3790:) I have 4CPU and 8GB of RAM. I have AWE enabled, /pae /3gb switch is on...
7
by: Lalasa | last post by:
Hi, Can anybody tell me how many cpu cycles File.copy would take and how many cpu cycles File.Move would take? CFile::Rename in C++ takes just one cpu cycle. As there is no File.Rename in C#,...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
68
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
1
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access...
6
by: tomtown.net | last post by:
Hello I'm trying to get a single line removed from a text file using a search pattern (pretty simple: if line contains "NODE1") -> remove line). To achieve this I's like to operate with only the...
17
by: shineofleo | last post by:
Here is the situation: I wrote a VB programm, which stores all the information in a single Access database file using jet engine. It worked well, however one of my customs reported that there was...
11
by: Jon Harrop | last post by:
Can read locks on a data structure be removed safely when updates are limited to replacing a reference? In other words, is setting a reference an atomic operation? I have been assuming that all...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.