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 3988012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:12:06+00:00 2026-05-20T06:12:06+00:00

i am extremely new to C# so excuse me if i don’t explain this

  • 0

i am extremely new to C# so excuse me if i don’t explain this well.

i’m retrieving images from my computer camera, and along with displaying them in a PictureBox, i’m encoding them to jpegs and sending them to a shared dictionary. here’s my code:

void CurrentCamera_OnImageCaptured(object sender, CameraEventArgs e)
        {
            this.pictureBoxMe.Image = e.Image;

            if (myName != "" && Form1.PicSent)
            {
                SendPic sendP = new SendPic((Image)e.Image.Clone());
                new System.Threading.Thread(new System.Threading.ThreadStart(sendP.send)).Start();
            }

        }

 public class SendPic
        {
            Image im;
            public SendPic (Image im)
            {
                this.im = im;
            }
            public void send(){

                Form1.PicSent = false;
                var memoryStream = new MemoryStream();

                im.Save(memoryStream, ImageFormat.Jpeg);

                var byteArray = memoryStream.ToArray();

                Form1.sd["/" + myName + "/video"] = byteArray;

                memoryStream.Close();
                Form1.PicSent = true;

            }
        }

the problem is that i’m getting the “Object is currently in use elsewhere.” error on the line: SendPic sendP = new SendPic((Image)e.Image.Clone());

based on other forum posts i’ve found, i already changed it so that the image is passed to the thread, and so that it’s a clone. however i’m still getting the same error (though it lasts longer before crashing now).

i read something about locking? how do i implement that in this case? or is there something else i need to do?

thanks.

  • 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-20T06:12:07+00:00Added an answer on May 20, 2026 at 6:12 am

    It behaves as though the OnImageCaptured method runs on a thread. Which isn’t unlikely for camera interfaces. Set a breakpoint and use the debugger’s Debug + Windows + Threads window to see what thread is running this code.

    The failure mode is then that the UI thread is accessing the image to paint the picture box, simultaneously with this worker thread calling Clone(). GDI+ does not permit two threads accessing the same image object at the same time. It would indeed be flaky, no telling at what exact moment in the time the UI thread starts painting. PicSent is another accident waiting to happen.

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

Sidebar

Related Questions

I'm extremely new to using jQuery/JavaScript, so please don't judge me if this is
I'm extremely new to CakePHP. From what I've gathered, it seems like I can
I'm extremely new to JS and have this code that I'm trying to tweak.
Before I start know this: I am extremely new to Java and programming. How
Ok, let me preface this question with the fact that I am extremely new
I am completely new to Web Development, still a student. Kindly bare this extremely
Please don't judge me, i'm extremely new on android developing... I wanna make an
I'm kind of new to this site and programming in general, so please excuse
I'm (extremely) new to Ruby, having started today. I just moved from my system's
Alright, I'm extremely new to programming so odds are this is a really easy

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.