Sleep thread from Main thread

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ipramod@gmail.com

    #1

    Sleep thread from Main thread

    Hi,

    I am having an application which inserts some data into a table. While
    inserting table rows, I want to check CPU percentage and if it is >90%
    then I want to sleep insertion for some time and then again resume
    it.

    For example:

    -Main execution starts
    -Main starts inserting rows into table
    -Check CPU %
    -while ( CPU % 90 )
    -Sleep(10000)
    -End inserting
    -End Main

    Now if I create one thead to insert table values and second thread to
    check CPU % from the main thread, then can we sleep the insertion
    thread from the main thead? Main thead waits till the insertion
    completes.

    Please let me know your thoughts or any other way to resolve this
    issue.

    Regards,
    PI
  • Alberto Poblacion

    #2
    Re: Sleep thread from Main thread

    <ipramod@gmail. comwrote in message
    news:f848cd63-6914-41a4-bf9e-e41571f46d02@s1 9g2000prg.googl egroups.com...
    [...]
    Please let me know your thoughts or any other way to resolve this
    issue.
    If your purpose is to avoid hogging the CPU with your insertion process,
    there is another alternative: You could create a thread to perform the
    insertion and set the Thread Priority to "BelowNorma l". In this way, when
    other processes require the CPU, your thread will automatically "give way"
    to them, and then immediately resume when the CPU is no longer busy at other
    tasks.

    Comment

    • Yasir Zaheer

      #3
      Re: Sleep thread from Main thread

      Hi,

      Alberto, gave a better alternative solution, you also can use the same
      code with Monitor involved, by using Monitor.Wait... . and
      Monitor.Pulse.. .. you can control the thread execution.

      Regards,

      On Dec 26, 3:48 pm, "Alberto Poblacion" <earthling-
      quitaestoparaco ntes...@poblaci on.orgwrote:
      <ipra...@gmail. comwrote in message
      >
      news:f848cd63-6914-41a4-bf9e-e41571f46d02@s1 9g2000prg.googl egroups.com...
      >
      [...]
      Please let me know your thoughts or any other way to resolve this
      issue.
      >
      If your purpose is to avoid hogging the CPU with your insertion process,
      there is another alternative: You could create a thread to perform the
      insertion and set the Thread Priority to "BelowNorma l". In this way, when
      other processes require the CPU, your thread will automatically "give way"
      to them, and then immediately resume when the CPU is no longer busy at other
      tasks.

      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: Sleep thread from Main thread

        Hi,

        Do not try to do the job of Windows, if the OS schedule 90% of CPU for a
        particular project it might be the case that no other process is using it in
        the first place.

        Not only that after you "restart" your thread it will be reach 90% again.
        so at the end what you are achieving is that instead of a short burst of 90%
        utilization you are having several chunks of high utilization.




        --
        Ignacio Machin
        The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

        Mobile & warehouse Solutions.
        <ipramod@gmail. comwrote in message
        news:f848cd63-6914-41a4-bf9e-e41571f46d02@s1 9g2000prg.googl egroups.com...
        Hi,
        >
        I am having an application which inserts some data into a table. While
        inserting table rows, I want to check CPU percentage and if it is >90%
        then I want to sleep insertion for some time and then again resume
        it.
        >
        For example:
        >
        -Main execution starts
        -Main starts inserting rows into table
        -Check CPU %
        -while ( CPU % 90 )
        -Sleep(10000)
        -End inserting
        -End Main
        >
        Now if I create one thead to insert table values and second thread to
        check CPU % from the main thread, then can we sleep the insertion
        thread from the main thead? Main thead waits till the insertion
        completes.
        >
        Please let me know your thoughts or any other way to resolve this
        issue.
        >
        Regards,
        PI

        Comment

        • Ignacio Machin \( .NET/ C# MVP \)

          #5
          Re: Sleep thread from Main thread

          Hi,


          I think that this si a better solution. Still I do not think that the
          original situation is a problem in the first place.

          --
          Ignacio Machin
          The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

          Mobile & warehouse Solutions.
          "Alberto Poblacion" <earthling-quitaestoparaco ntestar@poblaci on.orgwrote
          in message news:uS8Pez6RIH A.280@TK2MSFTNG P03.phx.gbl...
          <ipramod@gmail. comwrote in message
          news:f848cd63-6914-41a4-bf9e-e41571f46d02@s1 9g2000prg.googl egroups.com...
          >[...]
          >Please let me know your thoughts or any other way to resolve this
          >issue.
          >
          If your purpose is to avoid hogging the CPU with your insertion
          process, there is another alternative: You could create a thread to
          perform the insertion and set the Thread Priority to "BelowNorma l". In
          this way, when other processes require the CPU, your thread will
          automatically "give way" to them, and then immediately resume when the CPU
          is no longer busy at other tasks.
          >

          Comment

          Working...