Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Strategy for polling device on separate thread [Updated]

Strategy for polling device on separate thread [Updated]

Scheduled Pinned Locked Moved Design and Architecture
csharpquestionwpfdesignsysadmin
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BRShroyer
    wrote on last edited by
    #1

    I have an Ethernet connected motion controller that I need to get information from. I'm using WPF (C# flavor) for the project. The goal is to get data from the device as fast as possible so the UI doesn't seem sluggish. My thought was to spin off a background task that constantly polled the device for information as fast as it could run. It would fire events when certain groups of data were updated. Another class would monitor for these events and then set dependency properties that would update the UI. I have a couple questions: 1) What is the best way of starting the background task? I want it to close when the main thread is closed and not stop the main thread from being closed. 2) Any helpful advice as to how data can be retrieved on one thread that will eventually be displayed on a different thread. I have only toyed with multi-threaded applications up to this point. I'd rather ask and do it right than to find out later there was a better way. [UPDATES] This is on a closed network on the machine. It is not going over a corporate network. The device does not fire events. It has an API that allows data to be requested and then it replies. Right now I am using a DispatchTimer to request updates at a regular interval. It is running at 25ms without any issues. I was looking at trying to free my UI from my polling routine in case the device locks up or stops responding.

    Brad If you think you can, you will. If you think you can't, you won't. Either way, you're right.

    J B 2 Replies Last reply
    0
    • B BRShroyer

      I have an Ethernet connected motion controller that I need to get information from. I'm using WPF (C# flavor) for the project. The goal is to get data from the device as fast as possible so the UI doesn't seem sluggish. My thought was to spin off a background task that constantly polled the device for information as fast as it could run. It would fire events when certain groups of data were updated. Another class would monitor for these events and then set dependency properties that would update the UI. I have a couple questions: 1) What is the best way of starting the background task? I want it to close when the main thread is closed and not stop the main thread from being closed. 2) Any helpful advice as to how data can be retrieved on one thread that will eventually be displayed on a different thread. I have only toyed with multi-threaded applications up to this point. I'd rather ask and do it right than to find out later there was a better way. [UPDATES] This is on a closed network on the machine. It is not going over a corporate network. The device does not fire events. It has an API that allows data to be requested and then it replies. Right now I am using a DispatchTimer to request updates at a regular interval. It is running at 25ms without any issues. I was looking at trying to free my UI from my polling routine in case the device locks up or stops responding.

      Brad If you think you can, you will. If you think you can't, you won't. Either way, you're right.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      BRShroyer wrote:

      My thought was to spin off a background task that constantly polled the device for information as fast as it could run

      This is a very bad idea resulting in a very high system and network load. You should check if the motion controller provides some kind of notification messages (sending data to an established network connection). Using a worker thread for such network communications is the common and best way. To stop such a worker thread, it is usally listening for a terminate event (besides the communication events) that can be signaled when your application terminates. To pass data from the worker thread to the main (GUI) thread and vice-versa you must implement some kind of inter-thread communication. How to implement threads and inter-thread communication depends on the used language.

      B 1 Reply Last reply
      0
      • J Jochen Arndt

        BRShroyer wrote:

        My thought was to spin off a background task that constantly polled the device for information as fast as it could run

        This is a very bad idea resulting in a very high system and network load. You should check if the motion controller provides some kind of notification messages (sending data to an established network connection). Using a worker thread for such network communications is the common and best way. To stop such a worker thread, it is usally listening for a terminate event (besides the communication events) that can be signaled when your application terminates. To pass data from the worker thread to the main (GUI) thread and vice-versa you must implement some kind of inter-thread communication. How to implement threads and inter-thread communication depends on the used language.

        B Offline
        B Offline
        BRShroyer
        wrote on last edited by
        #3

        I've updated my post with some more information. Basically, this is on a closed network. There aren't any other devices connected. Also, this will be in C#. Thanks for the advice.

        Brad If you think you can, you will. If you think you can't, you won't. Either way, you're right.

        1 Reply Last reply
        0
        • B BRShroyer

          I have an Ethernet connected motion controller that I need to get information from. I'm using WPF (C# flavor) for the project. The goal is to get data from the device as fast as possible so the UI doesn't seem sluggish. My thought was to spin off a background task that constantly polled the device for information as fast as it could run. It would fire events when certain groups of data were updated. Another class would monitor for these events and then set dependency properties that would update the UI. I have a couple questions: 1) What is the best way of starting the background task? I want it to close when the main thread is closed and not stop the main thread from being closed. 2) Any helpful advice as to how data can be retrieved on one thread that will eventually be displayed on a different thread. I have only toyed with multi-threaded applications up to this point. I'd rather ask and do it right than to find out later there was a better way. [UPDATES] This is on a closed network on the machine. It is not going over a corporate network. The device does not fire events. It has an API that allows data to be requested and then it replies. Right now I am using a DispatchTimer to request updates at a regular interval. It is running at 25ms without any issues. I was looking at trying to free my UI from my polling routine in case the device locks up or stops responding.

          Brad If you think you can, you will. If you think you can't, you won't. Either way, you're right.

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          The System.Threading.Timer can help you: its callback function does not run in the thread the timer was created.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups