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. Help required in Threading..

Help required in Threading..

Scheduled Pinned Locked Moved C#
hardwaresaleshelpquestion
11 Posts 8 Posters 2 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.
  • N Offline
    N Offline
    NetMan2012
    wrote on last edited by
    #1

    hello, I am using Threads in my app that runs a process of writing data on Pole(Customer)-Display Hardware Device. Now this thread calls every single second. And what is happening is that the 1st thread have'nt write its content completely and 2nd thread called and it disturbs the 1st one as well. I have'nt played much with Threads, Can i make thread to wait in a way that If a thread is called it should check 1st that if any other thread already running the same method, it should wait for that thread to end. Thanks in Advance, Asfand

    S M M H 4 Replies Last reply
    0
    • N NetMan2012

      hello, I am using Threads in my app that runs a process of writing data on Pole(Customer)-Display Hardware Device. Now this thread calls every single second. And what is happening is that the 1st thread have'nt write its content completely and 2nd thread called and it disturbs the 1st one as well. I have'nt played much with Threads, Can i make thread to wait in a way that If a thread is called it should check 1st that if any other thread already running the same method, it should wait for that thread to end. Thanks in Advance, Asfand

      S Offline
      S Offline
      Stanciu Vlad
      wrote on last edited by
      #2

      Synchronization in multithreading environments can be done with semaphores[^] and mutexes[^]. Here[^] is a mutex example.

      I have no smart signature yet...

      1 Reply Last reply
      0
      • N NetMan2012

        hello, I am using Threads in my app that runs a process of writing data on Pole(Customer)-Display Hardware Device. Now this thread calls every single second. And what is happening is that the 1st thread have'nt write its content completely and 2nd thread called and it disturbs the 1st one as well. I have'nt played much with Threads, Can i make thread to wait in a way that If a thread is called it should check 1st that if any other thread already running the same method, it should wait for that thread to end. Thanks in Advance, Asfand

        M Offline
        M Offline
        mr mohsen
        wrote on last edited by
        #3

        yes you can configure the propertiese of your thread to wait for complete execute befor newest thread be running. the method is join() (ThreadName.join()). i hope this method help you to solve your problem.

        nobody help you... you have to help you yourself and this is success way.

        N 1 Reply Last reply
        0
        • N NetMan2012

          hello, I am using Threads in my app that runs a process of writing data on Pole(Customer)-Display Hardware Device. Now this thread calls every single second. And what is happening is that the 1st thread have'nt write its content completely and 2nd thread called and it disturbs the 1st one as well. I have'nt played much with Threads, Can i make thread to wait in a way that If a thread is called it should check 1st that if any other thread already running the same method, it should wait for that thread to end. Thanks in Advance, Asfand

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          If you are using a timer to initiate the threads then in the tick event you need to disable the timer till it is completed processing.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • N NetMan2012

            hello, I am using Threads in my app that runs a process of writing data on Pole(Customer)-Display Hardware Device. Now this thread calls every single second. And what is happening is that the 1st thread have'nt write its content completely and 2nd thread called and it disturbs the 1st one as well. I have'nt played much with Threads, Can i make thread to wait in a way that If a thread is called it should check 1st that if any other thread already running the same method, it should wait for that thread to end. Thanks in Advance, Asfand

            H Offline
            H Offline
            Henry Minute
            wrote on last edited by
            #5

            This might sound daft (it probably is :-D ) but if you cannot perform operation 2 until operation 1 has finished what on earth is the benefit of using threads?

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.

            L 1 Reply Last reply
            0
            • M mr mohsen

              yes you can configure the propertiese of your thread to wait for complete execute befor newest thread be running. the method is join() (ThreadName.join()). i hope this method help you to solve your problem.

              nobody help you... you have to help you yourself and this is success way.

              N Offline
              N Offline
              NetMan2012
              wrote on last edited by
              #6

              thnx alot, it worked :)

              realJSOPR 1 Reply Last reply
              0
              • N NetMan2012

                thnx alot, it worked :)

                realJSOPR Offline
                realJSOPR Offline
                realJSOP
                wrote on last edited by
                #7

                It seems to me that if the writing threa is busy, you swould be better advised to ignore the current write request, and just write when the thread isn't busy. Eventually, you're going to deadlock the machine because you're waiting for the thread to finish. You may even want to have the timer adjust its interval so that there's less of a chance of the thread being in a busy state.

                .45 ACP - because shooting twice is just silly
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                1 Reply Last reply
                0
                • H Henry Minute

                  This might sound daft (it probably is :-D ) but if you cannot perform operation 2 until operation 1 has finished what on earth is the benefit of using threads?

                  Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.

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

                  You're absolutely right. Simply having two threads continuously waiting one on the other isn't necessarily better than having just one thread handle everything. However, assuming a multi-core processor is used, a ping-pong approach (two buffers, one filled by the producer, one emptied by the consumer, and switching places based on an overall clock) could double the throughput. :)

                  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).


                  H 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    You're absolutely right. Simply having two threads continuously waiting one on the other isn't necessarily better than having just one thread handle everything. However, assuming a multi-core processor is used, a ping-pong approach (two buffers, one filled by the producer, one emptied by the consumer, and switching places based on an overall clock) could double the throughput. :)

                    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).


                    H Offline
                    H Offline
                    Henry Minute
                    wrote on last edited by
                    #9

                    Luc Pattyn wrote:

                    (two buffers, one filled by the producer, one emptied by the consumer, and switching places based on an overall clock) could double the throughput.

                    I thought something like that when I read the original question. There's probably a name for the technique, although I am not aware of it. Some form of Queue-like structure that the producers add their output to with a consumer that takes the head of the queue and displays it.

                    Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.

                    L L 2 Replies Last reply
                    0
                    • H Henry Minute

                      Luc Pattyn wrote:

                      (two buffers, one filled by the producer, one emptied by the consumer, and switching places based on an overall clock) could double the throughput.

                      I thought something like that when I read the original question. There's probably a name for the technique, although I am not aware of it. Some form of Queue-like structure that the producers add their output to with a consumer that takes the head of the queue and displays it.

                      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.

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

                      Producer-consumer[^] ?

                      1 Reply Last reply
                      0
                      • H Henry Minute

                        Luc Pattyn wrote:

                        (two buffers, one filled by the producer, one emptied by the consumer, and switching places based on an overall clock) could double the throughput.

                        I thought something like that when I read the original question. There's probably a name for the technique, although I am not aware of it. Some form of Queue-like structure that the producers add their output to with a consumer that takes the head of the queue and displays it.

                        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.

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

                        we've always referred to it as "ping-pong buffering" and that is also mentioned near the middle of this[^]. :)

                        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).


                        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