writing files in the Tick events when each write takes longer than the interval

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

    writing files in the Tick events when each write takes longer than the interval

    I have a timer. At each tick, say 0.1 second, I write a file.

    If it takes more than 0.1 second to write the file the app will not work
    correctly.

    How can I tell in the tick event if the previous file finished writing so I
    can skip writing at that time?

    I write using the Bitmap.Save method.

    Maybe I could Open, Write, Close synchronously??

    Any ideas?




    What happens if the Click event takes more that 0.3 seconds to exit.

    Do the click events pile up and then come right after each other or are the
    past ones simply missed?


    Thanks




  • rowe_newsgroups

    #2
    Re: writing files in the Tick events when each write takes longerthan the interval

    On Aug 1, 9:33 am, "AAaron123" <aaaron...@road runner.comwrote :
    I have a timer. At each tick, say 0.1 second, I write a file.
    >
    If it takes more than 0.1 second to write the file the app will not work
    correctly.
    >
    How can I tell in the tick event if the previous file finished writing soI
    can skip writing at that time?
    >
    I write using the Bitmap.Save method.
    >
    Maybe I could Open, Write, Close synchronously??
    >
    Any ideas?
    >
    What happens if  the Click event takes more that 0.3 seconds to exit.
    >
    Do the click events pile up and then come right after each other or are the
    past ones simply missed?
    >
    Thanks
    You need to find a solution that doesn't rely on time, otherwise you
    will spend the rest of the project's life debugging race conditions.

    Is it possible to use a message queue to track the writes? The tick
    event would write to the queue, and then the the changes could be
    written out from the queue asynchronously.

    Also, why not just keep the bitmap in memory and write it to a file
    when the changes are done?

    Thanks,

    Seth Rowe [MVP]

    Comment

    • Gillard

      #3
      Re: writing files in the Tick events when each write takes longer than the interval

      what about thread?

      "AAaron123" <aaaron123@road runner.comwrote in message
      news:e0KAws98IH A.5700@TK2MSFTN GP02.phx.gbl...
      I have a timer. At each tick, say 0.1 second, I write a file.
      >
      If it takes more than 0.1 second to write the file the app will not work
      correctly.
      >
      How can I tell in the tick event if the previous file finished writing so
      I can skip writing at that time?
      >
      I write using the Bitmap.Save method.
      >
      Maybe I could Open, Write, Close synchronously??
      >
      Any ideas?
      >
      >
      >
      >
      What happens if the Click event takes more that 0.3 seconds to exit.
      >
      Do the click events pile up and then come right after each other or are
      the past ones simply missed?
      >
      >
      Thanks
      >
      >
      >
      >

      Comment

      • Cor Ligthert[MVP]

        #4
        Re: writing files in the Tick events when each write takes longer than the interval

        Aaron,

        Why not do the writing of the file assynchronous in a backgroundworke r.

        The queue class will be a greath class to fullfil that.

        Cor

        "AAaron123" <aaaron123@road runner.comschre ef in bericht
        news:e0KAws98IH A.5700@TK2MSFTN GP02.phx.gbl...
        >I have a timer. At each tick, say 0.1 second, I write a file.
        >
        If it takes more than 0.1 second to write the file the app will not work
        correctly.
        >
        How can I tell in the tick event if the previous file finished writing so
        I can skip writing at that time?
        >
        I write using the Bitmap.Save method.
        >
        Maybe I could Open, Write, Close synchronously??
        >
        Any ideas?
        >
        >
        >
        >
        What happens if the Click event takes more that 0.3 seconds to exit.
        >
        Do the click events pile up and then come right after each other or are
        the past ones simply missed?
        >
        >
        Thanks
        >
        >
        >
        >

        Comment

        • AAaron123

          #5
          Re: writing files in the Tick events when each write takes longer than the interval

          Use a thread to write and check to see if the thread is still active??

          Is that what you mean?


          I'd have to learn how to do that but that would be a plus!

          Thanks

          "Gillard" <gillard_george s@@@@@@@@@hotma il.comwrote in message
          news:%23m43hz98 IHA.5404@TK2MSF TNGP04.phx.gbl. ..
          what about thread?
          >
          "AAaron123" <aaaron123@road runner.comwrote in message
          news:e0KAws98IH A.5700@TK2MSFTN GP02.phx.gbl...
          >I have a timer. At each tick, say 0.1 second, I write a file.
          >>
          >If it takes more than 0.1 second to write the file the app will not work
          >correctly.
          >>
          >How can I tell in the tick event if the previous file finished writing so
          >I can skip writing at that time?
          >>
          >I write using the Bitmap.Save method.
          >>
          >Maybe I could Open, Write, Close synchronously??
          >>
          >Any ideas?
          >>
          >>
          >>
          >>
          >What happens if the Click event takes more that 0.3 seconds to exit.
          >>
          >Do the click events pile up and then come right after each other or are
          >the past ones simply missed?
          >>
          >>
          >Thanks
          >>
          >>
          >>
          >>

          Comment

          • Gillard

            #6
            Re: writing files in the Tick events when each write takes longer than the interval

            do you write new image or it is the same image??

            "AAaron123" <aaaron123@road runner.comwrote in message
            news:#6OGr198IH A.1204@TK2MSFTN GP04.phx.gbl...
            Use a thread to write and check to see if the thread is still active??
            >
            Is that what you mean?
            >
            >
            I'd have to learn how to do that but that would be a plus!
            >
            Thanks
            >
            "Gillard" <gillard_george s@@@@@@@@@hotma il.comwrote in message
            news:%23m43hz98 IHA.5404@TK2MSF TNGP04.phx.gbl. ..
            >what about thread?
            >>
            >"AAaron123" <aaaron123@road runner.comwrote in message
            >news:e0KAws98I HA.5700@TK2MSFT NGP02.phx.gbl.. .
            >>I have a timer. At each tick, say 0.1 second, I write a file.
            >>>
            >>If it takes more than 0.1 second to write the file the app will not work
            >>correctly.
            >>>
            >>How can I tell in the tick event if the previous file finished writing
            >>so I can skip writing at that time?
            >>>
            >>I write using the Bitmap.Save method.
            >>>
            >>Maybe I could Open, Write, Close synchronously??
            >>>
            >>Any ideas?
            >>>
            >>>
            >>>
            >>>
            >>What happens if the Click event takes more that 0.3 seconds to exit.
            >>>
            >>Do the click events pile up and then come right after each other or are
            >>the past ones simply missed?
            >>>
            >>>
            >>Thanks
            >>>
            >>>
            >>>
            >>>
            >
            >

            Comment

            • AAaron123

              #7
              Re: writing files in the Tick events when each write takes longer than the interval


              Not sure what you mean about the queue. I'd have to save the images and the
              queue would write them?
              Is that what you mean.

              In my post I should have said: it is much like saving the frames of a movie.

              Thanks


              "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
              news:c99930ac-e6dc-4f8b-8a56-efe557fa049a@26 g2000hsk.google groups.com...
              On Aug 1, 9:33 am, "AAaron123" <aaaron...@road runner.comwrote :
              I have a timer. At each tick, say 0.1 second, I write a file.
              >
              If it takes more than 0.1 second to write the file the app will not work
              correctly.
              >
              How can I tell in the tick event if the previous file finished writing so
              I
              can skip writing at that time?
              >
              I write using the Bitmap.Save method.
              >
              Maybe I could Open, Write, Close synchronously??
              >
              Any ideas?
              >
              What happens if the Click event takes more that 0.3 seconds to exit.
              >
              Do the click events pile up and then come right after each other or are
              the
              past ones simply missed?
              >
              Thanks
              You need to find a solution that doesn't rely on time, otherwise you
              will spend the rest of the project's life debugging race conditions.

              Is it possible to use a message queue to track the writes? The tick
              event would write to the queue, and then the the changes could be
              written out from the queue asynchronously.





              Also, why not just keep the bitmap in memory and write it to a file
              when the changes are done?

              Thanks,

              Seth Rowe [MVP]



              Comment

              • rowe_newsgroups

                #8
                Re: writing files in the Tick events when each write takes longerthan the interval

                On Aug 1, 9:55 am, "AAaron123" <aaaron...@road runner.comwrote :
                Not sure what you mean about the queue. I'd have to save the images and the
                queue would write them?
                Is that what you mean.
                >
                In my post I should have said: it is much like saving the frames of a movie.
                >
                Thanks
                >
                "rowe_newsgroup s" <rowe_em...@yah oo.comwrote in message
                >
                news:c99930ac-e6dc-4f8b-8a56-efe557fa049a@26 g2000hsk.google groups.com...
                On Aug 1, 9:33 am, "AAaron123" <aaaron...@road runner.comwrote :
                >
                >
                >
                I have a timer. At each tick, say 0.1 second, I write a file.
                >
                If it takes more than 0.1 second to write the file the app will not work
                correctly.
                >
                How can I tell in the tick event if the previous file finished writing so
                I
                can skip writing at that time?
                >
                I write using the Bitmap.Save method.
                >
                Maybe I could Open, Write, Close synchronously??
                >
                Any ideas?
                >
                What happens if the Click event takes more that 0.3 seconds to exit.
                >
                Do the click events pile up and then come right after each other or are
                the
                past ones simply missed?
                >
                Thanks
                >
                You need to find a solution that doesn't rely on time, otherwise you
                will spend the rest of the project's life debugging race conditions.
                >
                Is it possible to use a message queue to track the writes? The tick
                event would write to the queue, and then the the changes could be
                written out from the queue asynchronously.
                >
                Also, why not just keep the bitmap in memory and write it to a file
                when the changes are done?
                >
                Thanks,
                >
                Seth Rowe [MVP]http://sethrowe.blogsp ot.com/
                At first take, yes you would need to save each bitmap into the queue
                and then write them to files asynchronously.

                Thanks,

                Seth Rowe [MVP]

                Comment

                • AAaron123

                  #9
                  Re: writing files in the Tick events when each write takes longer than the interval

                  thanks
                  "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
                  news:50b2992a-3438-4b6e-8940-f7fe40c36ba6@8g 2000hse.googleg roups.com...
                  On Aug 1, 9:55 am, "AAaron123" <aaaron...@road runner.comwrote :
                  Not sure what you mean about the queue. I'd have to save the images and
                  the
                  queue would write them?
                  Is that what you mean.
                  >
                  In my post I should have said: it is much like saving the frames of a
                  movie.
                  >
                  Thanks
                  >
                  "rowe_newsgroup s" <rowe_em...@yah oo.comwrote in message
                  >
                  news:c99930ac-e6dc-4f8b-8a56-efe557fa049a@26 g2000hsk.google groups.com...
                  On Aug 1, 9:33 am, "AAaron123" <aaaron...@road runner.comwrote :
                  >
                  >
                  >
                  I have a timer. At each tick, say 0.1 second, I write a file.
                  >
                  If it takes more than 0.1 second to write the file the app will not work
                  correctly.
                  >
                  How can I tell in the tick event if the previous file finished writing
                  so
                  I
                  can skip writing at that time?
                  >
                  I write using the Bitmap.Save method.
                  >
                  Maybe I could Open, Write, Close synchronously??
                  >
                  Any ideas?
                  >
                  What happens if the Click event takes more that 0.3 seconds to exit.
                  >
                  Do the click events pile up and then come right after each other or are
                  the
                  past ones simply missed?
                  >
                  Thanks
                  >
                  You need to find a solution that doesn't rely on time, otherwise you
                  will spend the rest of the project's life debugging race conditions.
                  >
                  Is it possible to use a message queue to track the writes? The tick
                  event would write to the queue, and then the the changes could be
                  written out from the queue asynchronously.
                  >
                  Also, why not just keep the bitmap in memory and write it to a file
                  when the changes are done?
                  >
                  Thanks,
                  >
                  Seth Rowe [MVP]http://sethrowe.blogsp ot.com/
                  At first take, yes you would need to save each bitmap into the queue
                  and then write them to files asynchronously.

                  Thanks,

                  Seth Rowe [MVP]



                  Comment

                  • AAaron123

                    #10
                    Re: writing files in the Tick events when each write takes longer than the interval

                    sorry, I should have said. A changing image but some may repeat. Missing
                    some is OK.

                    So should I use a thread to write and check to see if the thread is still
                    active and only write if it is not active?


                    Thanks

                    "Gillard" <gillard_george s@@@@@@@@@hotma il.comwrote in message
                    news:Odm6W398IH A.2060@TK2MSFTN GP02.phx.gbl...
                    do you write new image or it is the same image??
                    >
                    "AAaron123" <aaaron123@road runner.comwrote in message
                    news:#6OGr198IH A.1204@TK2MSFTN GP04.phx.gbl...
                    >Use a thread to write and check to see if the thread is still active??
                    >>
                    >Is that what you mean?
                    >>
                    >>
                    >I'd have to learn how to do that but that would be a plus!
                    >>
                    >Thanks
                    >>
                    >"Gillard" <gillard_george s@@@@@@@@@hotma il.comwrote in message
                    >news:%23m43hz9 8IHA.5404@TK2MS FTNGP04.phx.gbl ...
                    >>what about thread?
                    >>>
                    >>"AAaron123" <aaaron123@road runner.comwrote in message
                    >>news:e0KAws98 IHA.5700@TK2MSF TNGP02.phx.gbl. ..
                    >>>I have a timer. At each tick, say 0.1 second, I write a file.
                    >>>>
                    >>>If it takes more than 0.1 second to write the file the app will not
                    >>>work correctly.
                    >>>>
                    >>>How can I tell in the tick event if the previous file finished writing
                    >>>so I can skip writing at that time?
                    >>>>
                    >>>I write using the Bitmap.Save method.
                    >>>>
                    >>>Maybe I could Open, Write, Close synchronously??
                    >>>>
                    >>>Any ideas?
                    >>>>
                    >>>>
                    >>>>
                    >>>>
                    >>>What happens if the Click event takes more that 0.3 seconds to exit.
                    >>>>
                    >>>Do the click events pile up and then come right after each other or are
                    >>>the past ones simply missed?
                    >>>>
                    >>>>
                    >>>Thanks
                    >>>>
                    >>>>
                    >>>>
                    >>>>
                    >>
                    >>

                    Comment

                    • rowe_newsgroups

                      #11
                      Re: writing files in the Tick events when each write takes longerthan the interval

                      On Aug 1, 2:52 pm, "AAaron123" <aaaron...@road runner.comwrote :
                      thanks"rowe_new sgroups" <rowe_em...@yah oo.comwrote in message
                      >
                      news:50b2992a-3438-4b6e-8940-f7fe40c36ba6@8g 2000hse.googleg roups.com...
                      On Aug 1, 9:55 am, "AAaron123" <aaaron...@road runner.comwrote :
                      >
                      >
                      >
                      Not sure what you mean about the queue. I'd have to save the images and
                      the
                      queue would write them?
                      Is that what you mean.
                      >
                      In my post I should have said: it is much like saving the frames of a
                      movie.
                      >
                      Thanks
                      >
                      "rowe_newsgroup s" <rowe_em...@yah oo.comwrote in message
                      >
                      news:c99930ac-e6dc-4f8b-8a56-efe557fa049a@26 g2000hsk.google groups.com...
                      On Aug 1, 9:33 am, "AAaron123" <aaaron...@road runner.comwrote :
                      >
                      I have a timer. At each tick, say 0.1 second, I write a file.
                      >
                      If it takes more than 0.1 second to write the file the app will not work
                      correctly.
                      >
                      How can I tell in the tick event if the previous file finished writing
                      so
                      I
                      can skip writing at that time?
                      >
                      I write using the Bitmap.Save method.
                      >
                      Maybe I could Open, Write, Close synchronously??
                      >
                      Any ideas?
                      >
                      What happens if the Click event takes more that 0.3 seconds to exit.
                      >
                      Do the click events pile up and then come right after each other or are
                      the
                      past ones simply missed?
                      >
                      Thanks
                      >
                      You need to find a solution that doesn't rely on time, otherwise you
                      will spend the rest of the project's life debugging race conditions.
                      >
                      Is it possible to use a message queue to track the writes? The tick
                      event would write to the queue, and then the the changes could be
                      written out from the queue asynchronously.
                      >
                      Also, why not just keep the bitmap in memory and write it to a file
                      when the changes are done?
                      >
                      Thanks,
                      >
                      Seth Rowe [MVP]http://sethrowe.blogsp ot.com/
                      >
                      At first take, yes you would need to save each bitmap into the queue
                      and then write them to files asynchronously.
                      >
                      Thanks,
                      >
                      Seth Rowe [MVP]http://sethrowe.blogsp ot.com/
                      Also, please take a look at how your news reader does it's quoted
                      text, normally quoted lines have a '>' at the beginning, but yours are
                      missing. It makes it very hard to track conversations :-)

                      Thanks,

                      Seth Rowe [MVP]

                      Comment

                      • AAaron123

                        #12
                        Re: writing files in the Tick events when each write takes longer than the interval

                        Well, now I've got to read up on backgroundworke r message queue.


                        Thanks for the direction

                        "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                        news:86E2D4AD-F865-4074-B6C9-7F259FF5B277@mi crosoft.com...
                        Aaron,
                        >
                        Why not do the writing of the file assynchronous in a backgroundworke r.
                        >
                        The queue class will be a greath class to fullfil that.
                        >
                        Cor
                        >
                        "AAaron123" <aaaron123@road runner.comschre ef in bericht
                        news:e0KAws98IH A.5700@TK2MSFTN GP02.phx.gbl...
                        >>I have a timer. At each tick, say 0.1 second, I write a file.
                        >>
                        >If it takes more than 0.1 second to write the file the app will not work
                        >correctly.
                        >>
                        >How can I tell in the tick event if the previous file finished writing so
                        >I can skip writing at that time?
                        >>
                        >I write using the Bitmap.Save method.
                        >>
                        >Maybe I could Open, Write, Close synchronously??
                        >>
                        >Any ideas?
                        >>
                        >>
                        >>
                        >>
                        >What happens if the Click event takes more that 0.3 seconds to exit.
                        >>
                        >Do the click events pile up and then come right after each other or are
                        >the past ones simply missed?
                        >>
                        >>
                        >Thanks
                        >>
                        >>
                        >>
                        >>
                        >

                        Comment

                        • AAaron123

                          #13
                          Re: writing files in the Tick events when each write takes longer than the interval

                          My news reader must have it in for you.
                          Replies to others look OK.

                          Can't imagine what is going on!!!!


                          "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
                          news:92bd510c-54c4-4d41-9198-354093229f8e@f3 6g2000hsa.googl egroups.com...
                          On Aug 1, 2:52 pm, "AAaron123" <aaaron...@road runner.comwrote :
                          thanks"rowe_new sgroups" <rowe_em...@yah oo.comwrote in message
                          >
                          news:50b2992a-3438-4b6e-8940-f7fe40c36ba6@8g 2000hse.googleg roups.com...
                          On Aug 1, 9:55 am, "AAaron123" <aaaron...@road runner.comwrote :
                          >
                          >
                          >
                          Not sure what you mean about the queue. I'd have to save the images and
                          the
                          queue would write them?
                          Is that what you mean.
                          >
                          In my post I should have said: it is much like saving the frames of a
                          movie.
                          >
                          Thanks
                          >
                          "rowe_newsgroup s" <rowe_em...@yah oo.comwrote in message
                          >
                          news:c99930ac-e6dc-4f8b-8a56-efe557fa049a@26 g2000hsk.google groups.com...
                          On Aug 1, 9:33 am, "AAaron123" <aaaron...@road runner.comwrote :
                          >
                          I have a timer. At each tick, say 0.1 second, I write a file.
                          >
                          If it takes more than 0.1 second to write the file the app will not
                          work
                          correctly.
                          >
                          How can I tell in the tick event if the previous file finished writing
                          so
                          I
                          can skip writing at that time?
                          >
                          I write using the Bitmap.Save method.
                          >
                          Maybe I could Open, Write, Close synchronously??
                          >
                          Any ideas?
                          >
                          What happens if the Click event takes more that 0.3 seconds to exit.
                          >
                          Do the click events pile up and then come right after each other or
                          are
                          the
                          past ones simply missed?
                          >
                          Thanks
                          >
                          You need to find a solution that doesn't rely on time, otherwise you
                          will spend the rest of the project's life debugging race conditions.
                          >
                          Is it possible to use a message queue to track the writes? The tick
                          event would write to the queue, and then the the changes could be
                          written out from the queue asynchronously.
                          >
                          Also, why not just keep the bitmap in memory and write it to a file
                          when the changes are done?
                          >
                          Thanks,
                          >
                          Seth Rowe [MVP]http://sethrowe.blogsp ot.com/
                          >
                          At first take, yes you would need to save each bitmap into the queue
                          and then write them to files asynchronously.
                          >
                          Thanks,
                          >
                          Seth Rowe [MVP]http://sethrowe.blogsp ot.com/
                          Also, please take a look at how your news reader does it's quoted
                          text, normally quoted lines have a '>' at the beginning, but yours are
                          missing. It makes it very hard to track conversations :-)

                          Thanks,

                          Seth Rowe [MVP]



                          Comment

                          • rowe_newsgroups

                            #14
                            Re: writing files in the Tick events when each write takes longerthan the interval

                            My news reader must have it in for you.
                            Replies to others look OK.
                            LOL - just noticed that all other replies show up fine. Silly
                            newsreader and their vendetta's against me :-)

                            Thanks,

                            Seth Rowe [MVP]

                            Comment

                            • Cor Ligthert[MVP]

                              #15
                              Re: writing files in the Tick events when each write takes longer than the interval

                              Aaron

                              It is not a message queue, it is simple a queue.
                              You enque it in the mainthread and deque it in the background worker in a
                              loop.
                              and then you write the map that was in the file (B aware that is only a
                              reference before you think that it takes memory)

                              You have to test if it becomes empty, and filled again, because then you
                              have to restart it again.
                              Don't forget to synclock it while enqueing and dequing



                              Cor


                              "AAaron123" <aaaron123@road runner.comschre ef in bericht
                              news:%23lcpfiA9 IHA.3336@TK2MSF TNGP03.phx.gbl. ..
                              Well, now I've got to read up on backgroundworke r message queue.
                              >
                              >
                              Thanks for the direction
                              >
                              "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                              news:86E2D4AD-F865-4074-B6C9-7F259FF5B277@mi crosoft.com...
                              >Aaron,
                              >>
                              >Why not do the writing of the file assynchronous in a backgroundworke r.
                              >>
                              >The queue class will be a greath class to fullfil that.
                              >>
                              >Cor
                              >>
                              >"AAaron123" <aaaron123@road runner.comschre ef in bericht
                              >news:e0KAws98I HA.5700@TK2MSFT NGP02.phx.gbl.. .
                              >>>I have a timer. At each tick, say 0.1 second, I write a file.
                              >>>
                              >>If it takes more than 0.1 second to write the file the app will not work
                              >>correctly.
                              >>>
                              >>How can I tell in the tick event if the previous file finished writing
                              >>so I can skip writing at that time?
                              >>>
                              >>I write using the Bitmap.Save method.
                              >>>
                              >>Maybe I could Open, Write, Close synchronously??
                              >>>
                              >>Any ideas?
                              >>>
                              >>>
                              >>>
                              >>>
                              >>What happens if the Click event takes more that 0.3 seconds to exit.
                              >>>
                              >>Do the click events pile up and then come right after each other or are
                              >>the past ones simply missed?
                              >>>
                              >>>
                              >>Thanks
                              >>>
                              >>>
                              >>>
                              >>>
                              >>
                              >
                              >

                              Comment

                              Working...