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. Visual Basic
  4. Threading question; cross thread communication/invokation

Threading question; cross thread communication/invokation

Scheduled Pinned Locked Moved Visual Basic
questiondiscussion
5 Posts 2 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.
  • T Offline
    T Offline
    Tieske8
    wrote on last edited by
    #1

    I am working on a library that uses multiple threads to do all kinds of work. The work being done results in events being generated. Preferably I would like all communications to the outside world to be on a single thread, so most threading issues can be dealt with inside the library. When using forms there are the standard components with the Invoke methods that let the thread that runs the form call the requested Delegate, so whatever needs to be done (raise an event in my case) gets executed on that form thread. Is there a way to do this generically, without forms or components? Say I have 1 main thread that spawns 10 or 20 worker threads. And whenever the workers have an event to raise, they let the main thread do this? Is there an easy way (that I just haven't found), or should I be creating some custom threadpool management code to achieve this? Any thoughts?

    If you want something done fast, then do it right (Grissom, CSI) Thanks for your reply, you just acknowledged my existence

    L 1 Reply Last reply
    0
    • T Tieske8

      I am working on a library that uses multiple threads to do all kinds of work. The work being done results in events being generated. Preferably I would like all communications to the outside world to be on a single thread, so most threading issues can be dealt with inside the library. When using forms there are the standard components with the Invoke methods that let the thread that runs the form call the requested Delegate, so whatever needs to be done (raise an event in my case) gets executed on that form thread. Is there a way to do this generically, without forms or components? Say I have 1 main thread that spawns 10 or 20 worker threads. And whenever the workers have an event to raise, they let the main thread do this? Is there an easy way (that I just haven't found), or should I be creating some custom threadpool management code to achieve this? Any thoughts?

      If you want something done fast, then do it right (Grissom, CSI) Thanks for your reply, you just acknowledged my existence

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

      the BackgroundWorker class has this built-in: its ProgressChanged and RunWorkerCompleted handlers run on the thread that created the BGW. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      T 1 Reply Last reply
      0
      • L Luc Pattyn

        the BackgroundWorker class has this built-in: its ProgressChanged and RunWorkerCompleted handlers run on the thread that created the BGW. :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        T Offline
        T Offline
        Tieske8
        wrote on last edited by
        #3

        Thx for your time. I get your point, but... that would make my library capable of only raising the standard ProgressChanged and RunWorkerCompleted events, and not the custom events used in my library. Is there any description on how the BackgroundWorker class does its magic? that would allow me to re-create it and add my own events

        If you want something done fast, then do it right (Grissom, CSI) Thanks for your reply, you just acknowledged my existence

        L 1 Reply Last reply
        0
        • T Tieske8

          Thx for your time. I get your point, but... that would make my library capable of only raising the standard ProgressChanged and RunWorkerCompleted events, and not the custom events used in my library. Is there any description on how the BackgroundWorker class does its magic? that would allow me to re-create it and add my own events

          If you want something done fast, then do it right (Grissom, CSI) Thanks for your reply, you just acknowledged my existence

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

          BGW's internals are pretty complex; it uses System.ComponentModel.AsyncOperation, System.Threading.SynchronizationContext and System.Threading.ThreadPool and it basically boils down to a Delegate.Invoke You can see all that with a tool such as Reflector[^]. :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          T 1 Reply Last reply
          0
          • L Luc Pattyn

            BGW's internals are pretty complex; it uses System.ComponentModel.AsyncOperation, System.Threading.SynchronizationContext and System.Threading.ThreadPool and it basically boils down to a Delegate.Invoke You can see all that with a tool such as Reflector[^]. :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            T Offline
            T Offline
            Tieske8
            wrote on last edited by
            #5

            Meanwhile I ran some tests and my conclusion is that I cannot use the BackgroundWorker. Thing is with the BackgroundWorker, that the described behaviour is only valid in a windows forms application. If you run it in a forms application, the ProgressChanged handler indeed runs on the creator thread (the UI thread), but if you use it in a console application, the ProgressChanged handler runs on the DoWork background thread.

            If you want something done fast, then do it right (Grissom, CSI) Thanks for your reply, you just acknowledged my existence

            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