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. Backgroundworker with EventWaitHandle no respond????

Backgroundworker with EventWaitHandle no respond????

Scheduled Pinned Locked Moved C#
helpquestion
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.
  • M Offline
    M Offline
    mimimimilaw
    wrote on last edited by
    #1

    I am writing a windows application to upload file by using Backgroundworker and EventWaitHandle. But it doesn't get any respond after run the line 'handle.WaitOne();'. Can anyone help? private void btnUpload_Click(object sender, EventArgs e) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); MessageBox.Show("FTP 1"); worker.RunWorkerAsync(); MessageBox.Show("FTP 2"); handle.WaitOne(); // This blocks main thread MessageBox.Show("FTP 3"); } static void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { MessageBox.Show("FTP 4"); handle.Set(); }

    N 1 Reply Last reply
    0
    • M mimimimilaw

      I am writing a windows application to upload file by using Backgroundworker and EventWaitHandle. But it doesn't get any respond after run the line 'handle.WaitOne();'. Can anyone help? private void btnUpload_Click(object sender, EventArgs e) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); MessageBox.Show("FTP 1"); worker.RunWorkerAsync(); MessageBox.Show("FTP 2"); handle.WaitOne(); // This blocks main thread MessageBox.Show("FTP 3"); } static void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { MessageBox.Show("FTP 4"); handle.Set(); }

      N Offline
      N Offline
      Nicholas Butler
      wrote on last edited by
      #2

      One of the nice things about BackgroundWorker is that RunWorkerCompleted is raised on the UI thread. In your example, you have blocked the UI thread with the call to handle.WaitOne(), so worker_RunWorkerCompleted can never run and signal your handle :wtf: Also, the point of BackgroundWorker is to avoid blocking the UI thread. Why are you blocking it? Nick

      ---------------------------------- Be excellent to each other :)

      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