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. cross thread events

cross thread events

Scheduled Pinned Locked Moved C#
question
4 Posts 4 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.
  • S Offline
    S Offline
    spiritboy
    wrote on last edited by
    #1

    i have posted almost the same question earlier, but this one is more straitforward: i want to handle events that raise by thread1 and process them with thread2, that's all! or i want to command thread2 to do sth from thread1

    M L S 3 Replies Last reply
    0
    • S spiritboy

      i have posted almost the same question earlier, but this one is more straitforward: i want to handle events that raise by thread1 and process them with thread2, that's all! or i want to command thread2 to do sth from thread1

      M Offline
      M Offline
      Moreno Airoldi
      wrote on last edited by
      #2

      I had a look at your original post, and I think it will make it easier for you if you change your design a bit. If I uderstand correctly, you want to show your main form, and then show a splash screen right on top of it with a progress bar showing the advancement of some intialization work carried out by a background thread. Try this way: - Use the standard Main() for a Windows Form application, which will just run the app showing the main form (Form1). - In the Shown() event handler for Form1, show the splash screen (Form2), create your thread, link its events to functions in Form2 and start the thread. - When you get an event from the thread, use Invoke() to update the progress bar. As others told you, this is the best way to do that. - If you feel unsure about Invoke(), set up a thread-safe (using lock) property in Form2 and update it from the events handlers, then have a timer check it and update your progress bar. This is not good design, but it will work. I hope I got your problem correctly, and hope this can help you. :)

      2+2=5 for very large amounts of 2 (always loved that one hehe!)

      1 Reply Last reply
      0
      • S spiritboy

        i have posted almost the same question earlier, but this one is more straitforward: i want to handle events that raise by thread1 and process them with thread2, that's all! or i want to command thread2 to do sth from thread1

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

        This would be a producer-consumer problem[^] it's really common so I'm sure there are lots of articles about it on CP. Often implemented with a non-binary semaphore and a queue (or 2 semaphores and a circular buffer)

        1 Reply Last reply
        0
        • S spiritboy

          i have posted almost the same question earlier, but this one is more straitforward: i want to handle events that raise by thread1 and process them with thread2, that's all! or i want to command thread2 to do sth from thread1

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          If thread2 is a UI thread, all you need to do is call Invoke/BeginInvoke on one of the controls created on that thread. Otherwise, the typical way is to share a queue between the two threads, and have the second thread watch the queue and process commands as they come in.

          Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

          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