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. C#
  4. Multithreading

Multithreading

Scheduled Pinned Locked Moved C#
graphicsdesignquestion
3 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.
  • P Offline
    P Offline
    peropata
    wrote on last edited by
    #1

    Hi, I am new to multithreading, and I am considering implementing multithreading in my code. I am using MDI application with two child forms. On first child form I have all the controls and user interface (ChildForm1). Second child form is used for data analisys and drawing graphs (ChildForm2). ChildForm1 implements: 1) serial port communication (communication with microprocessor on PCB board) 2) data acquisition from intrument connected to computer (LAN) (up to 200ms for each data acquisition) 3) data processing and controls Currently I am using timer control to comminicate over serial port (10 times per second - checking the conditions), triggering data acquisition (when conditions are met) and finaly processing data and drawing graphs on another child form (real time). As I use single thread, I am experiencing some delays (application not running smoothly as it waits for comm process and data processing). What would be the right approach in setting multithread application ?

    L L 2 Replies Last reply
    0
    • P peropata

      Hi, I am new to multithreading, and I am considering implementing multithreading in my code. I am using MDI application with two child forms. On first child form I have all the controls and user interface (ChildForm1). Second child form is used for data analisys and drawing graphs (ChildForm2). ChildForm1 implements: 1) serial port communication (communication with microprocessor on PCB board) 2) data acquisition from intrument connected to computer (LAN) (up to 200ms for each data acquisition) 3) data processing and controls Currently I am using timer control to comminicate over serial port (10 times per second - checking the conditions), triggering data acquisition (when conditions are met) and finaly processing data and drawing graphs on another child form (real time). As I use single thread, I am experiencing some delays (application not running smoothly as it waits for comm process and data processing). What would be the right approach in setting multithread application ?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Yes. Create a new thread for data acquisition, read the data periodically in a new thread doesn't block the GUI. If new data is received, then fire event to your graph control and that control must update the GUI.

      1 Reply Last reply
      0
      • P peropata

        Hi, I am new to multithreading, and I am considering implementing multithreading in my code. I am using MDI application with two child forms. On first child form I have all the controls and user interface (ChildForm1). Second child form is used for data analisys and drawing graphs (ChildForm2). ChildForm1 implements: 1) serial port communication (communication with microprocessor on PCB board) 2) data acquisition from intrument connected to computer (LAN) (up to 200ms for each data acquisition) 3) data processing and controls Currently I am using timer control to comminicate over serial port (10 times per second - checking the conditions), triggering data acquisition (when conditions are met) and finaly processing data and drawing graphs on another child form (real time). As I use single thread, I am experiencing some delays (application not running smoothly as it waits for comm process and data processing). What would be the right approach in setting multithread application ?

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, There basically are two schemes you have to choose from. 1. if the timer is a Windows.Forms.Timer and your Tick handler is short (less than 10 msec), then everything should be OK. That requires there are no blocking I/O methods called. So when your peripheral needs 200 msec to perform a data acquisition, it would only work smoothly if that gets handled asynchronously, i.e. in one timer tick you issue a "start acquisition" command without waiting for the results; and in a different handler (or a later tick of the timer) you issue a "now deliver the available data" command. 2. If the above is not possible, the alternative is to have a second thread that takes care of communicating with your peripheral and preparing the new data; it should then use the Control.InvokeRequired/Invoke pattern to update the GUI. See this little article[^]. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read formatted code with indentation, so please use PRE tags for code snippets.


        I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


        modified on Monday, June 7, 2010 8:39 AM

        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