Can Time Ticks uniquely identify IIS requests?

T

Tim_Mac

hi,
i'm generating PDF files from crystal reports in my .Net 1.1 web site, and
saving them to disk for the user to download in their own time.

the format i'm currently using is: FileName_<DateTime.Now.Ticks>.PDF

there is a relatively low level of concurrent users on this site, but i am a
little concerned that two requests could happen within the same tick,
resulting in a filename clash and overwrite. is this possible? the docs
say a tick is 100 nanoseconds, which is a very short time i know. i have a
reasonable understanding of memory and disk access times, and the IIS/.Net
request life cycle, which would tell me that because disks are so relatively
slow, being measured in milliseconds, that IIS couldn't perform two
synchronous writes in the same tick. my nagging doubt is that two
simultaneous requests could run to the point in code where the file names
are calculated within the same tick, and then the disk I/O could be
executed.

i like having the Ticks in the file name because it is somewhat useful to me
that they are sequential. but if it is at all risky then i would change to
using a GUID in the filename.

any ideas? i know this is overkill to be concerned like this but i'm
interested anyway :)
many thanks in advance

tim mackey
 
L

Laurent Bugnion

Hi,

Tim_Mac said:
hi,
i'm generating PDF files from crystal reports in my .Net 1.1 web site, and
saving them to disk for the user to download in their own time.

the format i'm currently using is: FileName_<DateTime.Now.Ticks>.PDF

there is a relatively low level of concurrent users on this site, but i am a
little concerned that two requests could happen within the same tick,
resulting in a filename clash and overwrite. is this possible? the docs
say a tick is 100 nanoseconds, which is a very short time i know. i have a
reasonable understanding of memory and disk access times, and the IIS/.Net
request life cycle, which would tell me that because disks are so relatively
slow, being measured in milliseconds, that IIS couldn't perform two
synchronous writes in the same tick. my nagging doubt is that two
simultaneous requests could run to the point in code where the file names
are calculated within the same tick, and then the disk I/O could be
executed.

If you want to avoid concurrent access to a critical resource (in that
case, that would be the clock), you must use the lock statement. For
example, you could use a class to generate the file names and save the
files, and enclose the critical section in

lock ( this )
{
// ...
}

This will ensure a sequential execution.

However, the requests will be processed in sequential order too, so the
risk is zero IMHO.

If you really, really want to make sure that the ID is unique *and*
incrementing, why don't you simply add an index?

private static long lIndexOfFile = 0;

and then

string strFileName = "FileName_"
+ DateTime.Now.Ticks + lIndexOfFile++ + ".PDF";

HTH,
Laurent
 
W

Walter Wang [MSFT]

Hi Tim,

I would recommend to use GUID in the filename since DateTime.Now.Ticks is
not guaranteed to be unique.

By the way, is it supported in Crystal Reports to write the generated PDF
file to a stream instead of a file? If it's supported, then you may write
the PDF output the ASP.NET Response's output stream directly without using
a temporary file. Since Crystal Reports is not supported by Microsoft (see
http://support.microsoft.com/kb/100368/en-us for more info), you may have
to contact Crystal Reports for it.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Tim_Mac

hi,
Laurent, thanks for the tip on using lock, i hadn't considered that
approach.
i think i'll just go with the GUIDs as Walter has suggested. it will give me
slightly better security in terms of malicious users trying to guess the URL
of a temp file. i clear them out every day with a script but even still, my
user population isn't very trustworthy!

Walter i was originally streaming the exported Crystal Reports to the Http
response as you suggested, but i found that very large reports (1000 page
PDFs) caused major problems both on server and client, hanging requests etc.
since i moved to a file based approach i have not had any of these problems
so i trust it a lot more. it also allows users to download the file in
their own time, i can show the status message and provide a hyperlink to
download the file.

thanks again for your help.
tim
 

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,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top