I have some callback method that set on my queue some bitmap.
This callback is called every 3 millisecond.

What i mean is that my queue will be fill up with a new bitmap every 3 Millisecond.

I trying to get the first picture ( this is queue ... ) and show it on pictureBox - but i get some "external error " and i don't understand why.

public delegate void UpdateBitmapCallback( IntPtr img ); 

private void CallBack( object sender, IntPtr e )
        {
            lock( IncomingBmp )
            {
                IncomingBmp.Enqueue ( e );

                if( IncomingBmp.Count > 10)
                {
                    UpdateBitmap( IncomingBmp.Dequeue() );
                }
            }
        }

        private void UpdateBitmap( IntPtr img )
        {
            if( this.pictureBox1.InvokeRequired == true )
            {
                UpdateBitmapCallback p = new UpdateBitmapCallback( UpdateBitmap );
                this.Invoke( p, img );
            }
            else
            {
                this.pictureBox1.Image = Image.FromHbitmap( img );
            }   
        }

You are only storing a pointer (IntPtr) to the bitmap.
Are you sure that the bitmap still exists and is where it was when it was enqueued?
I.e. Is the pointer still valid?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.