Using the following code, we got the error ‘Object is currently in use elsewhere’
private void CaptureDone(System.Drawing.Bitmap e)
{
try
{
this.pictureBox.Image = e;
if (isSending)
ThreadPool.QueueUserWorkItem(new WaitCallback(SendVideoBuffer), pictureBox.Image);
}
catch (Exception) { }
}
void SendVideoBuffer(object bufferIn)
{
TcpClient tcp = new TcpClient(ConfigurationSettings.AppSettings[0].ToString(), 6000);
NetworkStream ns = tcp.GetStream();
if (ns != null)
{
System.Drawing.Image buffer = (System.Drawing.Image)bufferIn;
buffer.Save(ns, System.Drawing.Imaging.ImageFormat.Jpeg);// error comes here
ns.Close();
tcp.Close();
}
}
Please give suggestions.
GDI+ images are not thread safe, you need to aquire lock on the object.