running threads

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

    running threads

    Hi

    I'm writing an application which basically takes images from pixelink
    camera and does some calculations on them.

    I need to monitor the status of the system for 2 things: presence of
    camera and connection to SQL server.

    I also have a preview feature.

    Right now it's all being done by a two timers (one for preview and
    second for status) which run threads for status/preview.

    On a decent Core 2 duo everything is quite smooth but on single core CPU
    responsiveness of the application is not so good (sometimes main form is
    frozen for couple of seconds).

    How should i do those 2 processes so that they don't have an impact on
    application performance?

    Thx for any info!
  • =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=

    #2
    RE: running threads

    What type of Timer are you using? If it's Windows.Forms.T imer you're not
    using a background thread.

    Maybe you can provide some detailed code of what you're doing in your
    Tick/Elapsed event handlers?

    --
    Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

    Microsoft MVP, Visual Developer - Visual C#


    "garther" wrote:
    Hi
    >
    I'm writing an application which basically takes images from pixelink
    camera and does some calculations on them.
    >
    I need to monitor the status of the system for 2 things: presence of
    camera and connection to SQL server.
    >
    I also have a preview feature.
    >
    Right now it's all being done by a two timers (one for preview and
    second for status) which run threads for status/preview.
    >
    On a decent Core 2 duo everything is quite smooth but on single core CPU
    responsiveness of the application is not so good (sometimes main form is
    frozen for couple of seconds).
    >
    How should i do those 2 processes so that they don't have an impact on
    application performance?
    >
    Thx for any info!
    >

    Comment

    • garther

      #3
      Re: running threads

      In the timer i'm running a thread

      ---
      Thread Status = new Thread(statusJo b);
      Status.Start():
      ----


      Peter Ritchie [C# MVP] pisze:
      What type of Timer are you using? If it's Windows.Forms.T imer you're not
      using a background thread.
      >
      Maybe you can provide some detailed code of what you're doing in your
      Tick/Elapsed event handlers?
      >

      Comment

      • Peter Duniho

        #4
        Re: running threads

        On Wed, 19 Mar 2008 10:12:30 -0700, garther <marcinp@cpartn er.plwrote:
        In the timer i'm running a thread
        >
        ---
        Thread Status = new Thread(statusJo b);
        Status.Start():
        ----
        Why are you doing that? If you need for the timer event to be handled on
        a separate thread, then use Threading.Timer which already runs the timer
        event code on a different thread (it uses a thread pool thread). Starting
        a whole new thread every time the timer elapses is wasteful and
        unnecessary.

        As Peter R. said, you really ought to be more specific about what you're
        doing. Without describing in detail what timer you're using, how you're
        using it, and what your code does in response to the timer, it's
        impossible to suggest what might be causing the issue you're seeing.

        Pete

        Comment

        • =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=

          #5
          Re: running threads

          It's hard to say what the problem could be with such little to go on.

          I agree with Peter though, spawning an new thread on ever Timer tick isn't
          the most efficient method.

          --
          Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

          Microsoft MVP, Visual Developer - Visual C#


          "garther" wrote:
          In the timer i'm running a thread
          >
          ---
          Thread Status = new Thread(statusJo b);
          Status.Start():
          ----
          >
          >
          Peter Ritchie [C# MVP] pisze:
          What type of Timer are you using? If it's Windows.Forms.T imer you're not
          using a background thread.

          Maybe you can provide some detailed code of what you're doing in your
          Tick/Elapsed event handlers?
          >

          Comment

          • garther

            #6
            Re: running threads

            So what method would you suggest for this purpose?


            Peter Ritchie [C# MVP] pisze:
            It's hard to say what the problem could be with such little to go on.
            >
            I agree with Peter though, spawning an new thread on ever Timer tick isn't
            the most efficient method.
            >

            Comment

            • Peter Duniho

              #7
              Re: running threads

              On Wed, 19 Mar 2008 13:03:14 -0700, garther <marcinp@cpartn er.plwrote:
              So what method would you suggest for this purpose?
              Well, you haven't bothered to answer the questions asked you, including
              "What type of Timer are you using?" The other relevant question asked but
              not yet answered is "what are you doing in your elapsed event handlers?"

              The only thing you've posted so far is code that suggests you're creating
              a whole new thread every time the timer fires. From what little
              information you've shared so far, it's impossible to tell you exactly how
              to fix that, but it's pretty easy to know that it's almost certainly wrong
              to do it the way you're doing it.

              Pete

              Comment

              Working...