Results 1 to 16 of 16

Thread: Baffling error in Background worker code

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2021
    Posts
    6

    Baffling error in Background worker code

    Variables:
    Source and Destination are both bitmaps that are the same size
    hgt and wid are the height and width of the images minus 1

    Here's the background worker Code:
    Code:
    Private Sub BGWProcess_DoWork(sender As Object, e As DoWorkEventArgs) Handles BGWProcess.DoWork`
      For Y = 0 To hgt
     For X = 0 To wid
    If BGWProcess.CancellationPending Then Exit Sub
    Destination.SetPixel(X, Y, Source.GetPixel(X, Y)) 'Here is where it fails
     Next
    BGWProcess.ReportProgress(Y)
      Next
    End Sub
    
    Private Sub BGWProcess_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BGWProcess.ProgressChanged
    TxtProgress.Text = e.ProgressPercentage.ToString
    PictureBox1.Image = Destination
    End Sub
    The exception is "System.InvalidOperationException: Object is currently in use elsewhere."
    at the line "Destination.SetPixel(X, Y, Source.GetPixel(X, Y))
    There is nothing else going on that might be accessing any of the bitmaps or the PictureBox. Any ideas would be greatly appreciated.
    Last edited by Shaggy Hiker; Aug 31st, 2024 at 10:14 PM. Reason: Added CODE tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width