Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 551713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:25:23+00:00 2026-05-13T11:25:23+00:00

I am currently working on a Windows.Forms application. It’s basically a simple motion detection

  • 0

I am currently working on a Windows.Forms application. It’s basically a simple motion detection problem.

I have a button on a form, that when pressed launches a background worker that does the following :

  1. Fetch an image from disk
  2. Create a new bitmap, to be used as the buffer.
  3. Perform Motion Detection
  4. From the results of Motion Detection, update the buffer (using the buffer’s drawing surface)
  5. Fire the Progress Changed Event with an argument consisting of a clone of the buffer, basically (sender as BackgroundWorker).ReportProgress((Bitmap)buffer.Clone())

In the Progress Changed Event, I then draw the buffer to screen.

if (!PnlImage.IsDisposed)
            PnlImage.CreateGraphics().DrawImageUnscaled(buffer, 0, 0);

I can’t help wondering if this is the best way to draw the updated image on the screen. Can anyone suggest any improvements I can make?
Thanks.

EDIT :
I have since updated the program to use the .NET Framework 4, and we’re no longer using a BackgroundWorker. Instead, we are now using the System.Threading.Tasks namespaces, and using Invoke to update the background image from within the task.

Thanks to all replies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:25:24+00:00Added an answer on May 13, 2026 at 11:25 am

    I believe the root of any problems you may be experiencing is the fact that any GUI updates must be done on the UI thread. You cannot safely update the UI from another thread. So, basically, you need to do something like the following (I’m just changing the background color as an example, but you can do whatever you like):

        private void SomethingCalledFromBackgroundThread()
        {
            panel1.Invoke(new DoUpdatePanel(UpdatePanel), Color.Blue);
        }
    
        private delegate void DoUpdatePanel(Color aColor);
    
        private void UpdatePanel(Color aColor)
        {
            panel1.BackColor = aColor;
        }
    

    ============ Update =======>

    @Ash you have mischaracterized my answer. I did not say to call Invoke from within ProgressChanged. @Jean keep in mind that ReportProgress/ProgressChanged is being run asynchronously–which is why you find yourself making a clone of your image. This would not be necessary if you use Invoke from within your background thread, rather than ReportProgress.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try Django. It's one of the more popular Python web… May 14, 2026 at 4:59 pm
  • Editorial Team
    Editorial Team added an answer There is nothing you can do. Your content management system… May 14, 2026 at 4:59 pm
  • Editorial Team
    Editorial Team added an answer If the intention is to incorporate your SIP stack into… May 14, 2026 at 4:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.