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. Managed C++/CLI
  4. crossing thread boundary

crossing thread boundary

Scheduled Pinned Locked Moved Managed C++/CLI
question
2 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.
  • A Offline
    A Offline
    aljodav
    wrote on last edited by
    #1

    Can I send text from a BackgroundWorker::DoWork() to a listbox in the main thread ? I want to keep the listbox in the main thread up to date with what's going on in BackgroundWorker::DoWork(). The BackgroundWorker::ProgressChanged() hasn't the parameter I need ( String^ ) and if I send the text straight to the listbox, an exception is raised. If not, is there another way to do it ?

    L 1 Reply Last reply
    0
    • A aljodav

      Can I send text from a BackgroundWorker::DoWork() to a listbox in the main thread ? I want to keep the listbox in the main thread up to date with what's going on in BackgroundWorker::DoWork(). The BackgroundWorker::ProgressChanged() hasn't the parameter I need ( String^ ) and if I send the text straight to the listbox, an exception is raised. If not, is there another way to do it ?

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

      As a general rule you can only touch GUI objects from the thread that created them. Use BeginInvoke() method on the form to transfer the call to the GUI thread and update the listbox from there. Once in the GUI thread check for IsDisposed before updating the listbox as its possible for the form to be destroyed beteen you calling BeginInvoke and the actual function being called by the GUI thread

      System.IO.Path.IsPathRooted() does not behave as I would expect

      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