Can Time Ticks uniquely identify IIS requests?

Discussion in 'ASP .Net' started by Tim_Mac, Sep 11, 2006.

  1. Tim_Mac

    Tim_Mac Guest

    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
     
    Tim_Mac, Sep 11, 2006
    #1
    1. Advertising

  2. Hi,

    Tim_Mac wrote:
    > 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
    --
    Laurent Bugnion, GalaSoft
    Software engineering: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion, Sep 11, 2006
    #2
    1. Advertising

  3. 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 (, 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.
     
    Walter Wang [MSFT], Sep 12, 2006
    #3
  4. Tim_Mac

    Tim_Mac Guest

    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


    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > 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 (, 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.
    >
     
    Tim_Mac, Sep 12, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    638
    Curt_C [MVP]
    Jul 27, 2004
  2. Alan Silver

    How do I uniquely identify a control?

    Alan Silver, Feb 24, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    474
    Alan Silver
    Feb 24, 2005
  3. bazzer
    Replies:
    0
    Views:
    549
    bazzer
    Apr 10, 2006
  4. bazzer
    Replies:
    8
    Views:
    1,621
    kruch
    Mar 23, 2007
  5. Lord0
    Replies:
    0
    Views:
    1,058
    Lord0
    Oct 25, 2006
Loading...

Share This Page