Home > Net >  ! Genuflect is begged! ! Genuflect is begged! VB picturebox Graphics. FromImage objects are using
! Genuflect is begged! ! Genuflect is begged! VB picturebox Graphics. FromImage objects are using

Time:09-22

Two Picturebox corresponding vice thread, only run a Picturebox, or the two together, occasionally appear Graphics. FromImage, are using error, System. InvalidOperationException: object is currently used elsewhere,
In the System. Drawing. Graphics. FromImage (Image Image)

Private Sub BgDrawPicturebox2_DoWork (ByVal sender As System. Object, ByVal e As System.Com ponentModel. DoWorkEventArgs) Handles BgDrawPicturebox2. DoWork

PictureBox2. Refresh ()

Dim g3 As Graphics
Dim bmp3 As Bitmap
Bmp3=New Bitmap (470, 240)
PictureBox2. Image=bmp3
G3=Graphics. FromImage (PictureBox2. Image)

DrawOrdinate2 (g3, 1, 5, 35, 220, 435, 20)
DrawaxisValue2 (g3)
Drawtarget2 (1, g3)

G3. The Dispose ()
System. The Threading. Thread.sleep (300)

End Sub

CodePudding user response:

Crying that

CodePudding user response:

And two threads code about the same, similar to the above, and I was done a single thread, another thread

CodePudding user response:

G3. The Dispose ()
Bmp3. The Dispose ()

CodePudding user response:

Because it is said to use, as in other places System. Drawing, Graphics. FromImage Image (Image), which is the Image, used in other places, only use the PictureBox2 here. The Image=bmp3, in addition to loading dialog, look at the others, the method of changing PictureBox2. Image=bmp3, clone, and on the behind, in front of the g3=Graphics. FromImage (bmp3), is ok

CodePudding user response:

The next thread must can begin after a thread on the harness, won't appear this problem

CodePudding user response:

I encountered a similar problem
The third floor of the dispose and then performing a garbage collection command should be no problem, this command is not commonly used, not remember, the Internet search

CodePudding user response:

Multithreading does appear this problem, I also met before, don't know how to solve, I will add the thread lock in
  • Related