File Share Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • > Adrian

    File Share Question

    In an application in which FileShare is set.
    Is it possible to go to say a file conntrol block
    to ascertain the condition of the file, ie. if
    someone else is working with the file? Or is
    is it necessary to do all writing (not reading)
    in a loop in which the user is kept till the
    file is free again?

    Adrian.


  • Spam Catcher

    #2
    Re: File Share Question

    "Adrian <" <not@all.access iblewrote in news:45599e79$0 $749$5fc3050
    @dreader2.news. tiscali.nl:
    In an application in which FileShare is set.
    Is it possible to go to say a file conntrol block
    to ascertain the condition of the file, ie. if
    someone else is working with the file? Or is
    is it necessary to do all writing (not reading)
    in a loop in which the user is kept till the
    file is free again?

    I believe if your filestream remains open - and depending on which mode you
    have the filestream set to, you'll have control over the file.

    Comment

    • > Adrian

      #3
      Re: File Share Question


      "Spam Catcher" <spamhoneypot@r ogers.comwrote in message
      news:Xns987C276 F1A416usenethon eypotrogers@127 .0.0.1...
      "Adrian <" <not@all.access iblewrote in news:45599e79$0 $749$5fc3050
      @dreader2.news. tiscali.nl:
      >
      In an application in which FileShare is set.
      Is it possible to go to say a file conntrol block
      to ascertain the condition of the file, ie. if
      someone else is working with the file? Or is
      is it necessary to do all writing (not reading)
      in a loop in which the user is kept till the
      file is free again?
      >
      >
      Hi,

      If a FileShare parameter is used and a
      file is opened permitting others to read only,
      what happens if some one tries to modify
      the file, will he be set to wait in a loop
      or will he get an error message?

      Adrian.




      Comment

      • Rad [Visual C# MVP]

        #4
        Re: File Share Question

        I believe the .NEt framework will throw an exception if you try and open a
        file for writing that has been opened elswjere for read only

        --


        Bits. Bytes.

        ------------------------------
        Hi,
        >
        If a FileShare parameter is used and a
        file is opened permitting others to read only,
        what happens if some one tries to modify
        the file, will he be set to wait in a loop
        or will he get an error message?
        >
        Adrian.
        >
        >
        >
        >
        >

        Comment

        • Spam Catcher

          #5
          Re: File Share Question

          "Adrian <" <not@all.access iblewrote in news:455af913$0 $750$5fc3050
          @dreader2.news. tiscali.nl:
          If a FileShare parameter is used and a
          file is opened permitting others to read only,
          what happens if some one tries to modify
          the file, will he be set to wait in a loop
          or will he get an error message?
          ..NET will throw an exception.

          Comment

          • > Adrian

            #6
            Re: File Share Question

            Ok, thanks.
            I think I have soved the problem by adding
            code like so:

            While(!fs.CanRe ad){}

            That will keep the user waiting just a little
            while till the file is free again. At least,
            that is my expectation :)

            (For the non-filestream files I have written
            a simple block / unblock routine.)

            Thank you again

            Adrian.


            "Spam Catcher" <spamhoneypot@r ogers.comwrote in message
            news:Xns987CA68 BE3B32usenethon eypotrogers@127 .0.0.1...
            "Adrian <" <not@all.access iblewrote in news:455af913$0 $750$5fc3050
            @dreader2.news. tiscali.nl:
            >
            If a FileShare parameter is used and a
            file is opened permitting others to read only,
            what happens if some one tries to modify
            the file, will he be set to wait in a loop
            or will he get an error message?
            >
            .NET will throw an exception.

            Comment

            • Dave Sexton

              #7
              Re: File Share Question

              Hi Adrian,

              You might want to let some other threads get some processor time as well by
              putting the thread to sleep:

              while (!fs.CanRead)
              {
              System.Threadin g.Thread.Curren t.Sleep(200);
              }

              --
              Dave Sexton

              "Adrian <" <not@all.access iblewrote in message
              news:455b8f84$0 $739$5fc3050@dr eader2.news.tis cali.nl...
              Ok, thanks.
              I think I have soved the problem by adding
              code like so:
              >
              While(!fs.CanRe ad){}
              >
              That will keep the user waiting just a little
              while till the file is free again. At least,
              that is my expectation :)
              >
              (For the non-filestream files I have written
              a simple block / unblock routine.)
              >
              Thank you again
              >
              Adrian.
              >
              >
              "Spam Catcher" <spamhoneypot@r ogers.comwrote in message
              news:Xns987CA68 BE3B32usenethon eypotrogers@127 .0.0.1...
              >"Adrian <" <not@all.access iblewrote in news:455af913$0 $750$5fc3050
              >@dreader2.news .tiscali.nl:
              >>
              If a FileShare parameter is used and a
              file is opened permitting others to read only,
              what happens if some one tries to modify
              the file, will he be set to wait in a loop
              or will he get an error message?
              >>
              >.NET will throw an exception.
              >
              >

              Comment

              • > Adrian

                #8
                Re: File Share Question

                "Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
                news:ep1jPRkCHH A.4832@TK2MSFTN GP06.phx.gbl...
                Hi Adrian,
                >
                You might want to let some other threads get some processor time as well
                by
                putting the thread to sleep:
                >
                while (!fs.CanRead)
                {
                System.Threadin g.Thread.Curren t.Sleep(200);
                }
                >
                *************** *************** ***
                That is good advice, Thank you for it.
                Adrian.


                Comment

                • > Adrian

                  #9
                  Re: File Share Question

                  Your suggestion generated an error.
                  ("... cannot be accessed as an instance reference ...")
                  Would System.Threadin g.Thread.Sleep( 200);
                  be ok as well?

                  Please advise.

                  Adrian.




                  "Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
                  news:ep1jPRkCHH A.4832@TK2MSFTN GP06.phx.gbl...
                  Hi Adrian,
                  >
                  You might want to let some other threads get some processor time as well
                  by
                  putting the thread to sleep:
                  >
                  while (!fs.CanRead)
                  {
                  System.Threadin g.Thread.Curren t.Sleep(200);
                  }
                  >
                  --
                  Dave Sexton
                  >
                  "Adrian <" <not@all.access iblewrote in message
                  news:455b8f84$0 $739$5fc3050@dr eader2.news.tis cali.nl...
                  Ok, thanks.
                  I think I have soved the problem by adding
                  code like so:

                  While(!fs.CanRe ad){}

                  That will keep the user waiting just a little
                  while till the file is free again. At least,
                  that is my expectation :)

                  (For the non-filestream files I have written
                  a simple block / unblock routine.)

                  Thank you again

                  Adrian.


                  "Spam Catcher" <spamhoneypot@r ogers.comwrote in message
                  news:Xns987CA68 BE3B32usenethon eypotrogers@127 .0.0.1...
                  "Adrian <" <not@all.access iblewrote in news:455af913$0 $750$5fc3050
                  @dreader2.news. tiscali.nl:
                  >
                  If a FileShare parameter is used and a
                  file is opened permitting others to read only,
                  what happens if some one tries to modify
                  the file, will he be set to wait in a loop
                  or will he get an error message?
                  >
                  .NET will throw an exception.
                  >
                  >

                  Comment

                  • Dave Sexton

                    #10
                    Re: File Share Question

                    Hi,

                    Yes, sorry. I wrote that off the top of my head, which apparently is the
                    stupid part ;)

                    --
                    Dave Sexton

                    "Adrian <" <not@all.access iblewrote in message
                    news:455e0585$0 $715$5fc3050@dr eader2.news.tis cali.nl...
                    Your suggestion generated an error.
                    ("... cannot be accessed as an instance reference ...")
                    Would System.Threadin g.Thread.Sleep( 200);
                    be ok as well?
                    >
                    Please advise.
                    >
                    Adrian.
                    >
                    >
                    >
                    >
                    "Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
                    news:ep1jPRkCHH A.4832@TK2MSFTN GP06.phx.gbl...
                    >Hi Adrian,
                    >>
                    >You might want to let some other threads get some processor time as well
                    by
                    >putting the thread to sleep:
                    >>
                    >while (!fs.CanRead)
                    >{
                    > System.Threadin g.Thread.Curren t.Sleep(200);
                    >}
                    >>
                    >--
                    >Dave Sexton
                    >>
                    >"Adrian <" <not@all.access iblewrote in message
                    >news:455b8f84$ 0$739$5fc3050@d reader2.news.ti scali.nl...
                    Ok, thanks.
                    I think I have soved the problem by adding
                    code like so:
                    >
                    While(!fs.CanRe ad){}
                    >
                    That will keep the user waiting just a little
                    while till the file is free again. At least,
                    that is my expectation :)
                    >
                    (For the non-filestream files I have written
                    a simple block / unblock routine.)
                    >
                    Thank you again
                    >
                    Adrian.
                    >
                    >
                    "Spam Catcher" <spamhoneypot@r ogers.comwrote in message
                    news:Xns987CA68 BE3B32usenethon eypotrogers@127 .0.0.1...
                    >"Adrian <" <not@all.access iblewrote in news:455af913$0 $750$5fc3050
                    >@dreader2.news .tiscali.nl:
                    >>
                    If a FileShare parameter is used and a
                    file is opened permitting others to read only,
                    what happens if some one tries to modify
                    the file, will he be set to wait in a loop
                    or will he get an error message?
                    >>
                    >.NET will throw an exception.
                    >
                    >
                    >>
                    >>
                    >
                    >

                    Comment

                    • > Adrian

                      #11
                      Re: File Share Question

                      :))

                      Adian

                      "Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
                      news:OHtRLUoCHH A.1196@TK2MSFTN GP02.phx.gbl...
                      Hi,
                      >
                      Yes, sorry. I wrote that off the top of my head, which apparently is the
                      stupid part ;)
                      >
                      --
                      Dave Sexton
                      >
                      "Adrian <" <not@all.access iblewrote in message
                      news:455e0585$0 $715$5fc3050@dr eader2.news.tis cali.nl...
                      Your suggestion generated an error.
                      ("... cannot be accessed as an instance reference ...")
                      Would System.Threadin g.Thread.Sleep( 200);
                      be ok as well?

                      Please advise.

                      Adrian.




                      "Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
                      news:ep1jPRkCHH A.4832@TK2MSFTN GP06.phx.gbl...
                      Hi Adrian,
                      >
                      You might want to let some other threads get some processor time as
                      well
                      by
                      putting the thread to sleep:
                      >
                      while (!fs.CanRead)
                      {
                      System.Threadin g.Thread.Curren t.Sleep(200);
                      }
                      >
                      --
                      Dave Sexton
                      >
                      "Adrian <" <not@all.access iblewrote in message
                      news:455b8f84$0 $739$5fc3050@dr eader2.news.tis cali.nl...
                      Ok, thanks.
                      I think I have soved the problem by adding
                      code like so:

                      While(!fs.CanRe ad){}

                      That will keep the user waiting just a little
                      while till the file is free again. At least,
                      that is my expectation :)

                      (For the non-filestream files I have written
                      a simple block / unblock routine.)

                      Thank you again

                      Adrian.


                      "Spam Catcher" <spamhoneypot@r ogers.comwrote in message
                      news:Xns987CA68 BE3B32usenethon eypotrogers@127 .0.0.1...
                      "Adrian <" <not@all.access iblewrote in
                      news:455af913$0 $750$5fc3050
                      @dreader2.news. tiscali.nl:
                      >
                      If a FileShare parameter is used and a
                      file is opened permitting others to read only,
                      what happens if some one tries to modify
                      the file, will he be set to wait in a loop
                      or will he get an error message?
                      >
                      .NET will throw an exception.


                      >
                      >
                      >
                      >

                      Comment

                      Working...