multithreading - "Cross-thread operation not valid" - Except, I'm not performing a cross-thread operation. C# -


i've seen lot of suggestions resolving error:

"an exception of type 'system.invalidoperationexception' occurred in system.windows.forms.dll not handled in user code

additional information: cross-thread operation not valid: control 'picturebox4' accessed thread other thread created on."

the problem is, issue doesn't apply solutions i've seen. not cross-thread operation. here's code:

private void green()     {         // declare initial variables          int xgreen = 64;          // bitmap picturebox         bitmap bmp = (bitmap)picturebox4.image;          // search through each pixel via x, y coordinates, examine , make changes. dont let values exceed 255 or fall under 0.           (int y = 0; y < bmp.height; y++)             (int x = 0; x < bmp.width; x++)             {                 color c = bmp.getpixel(x, y);                 int myred = c.r, mygreen = c.g, myblue = c.b;                 mygreen += xgreen;                 if (mygreen > 255)                     mygreen = 255;                 bmp.setpixel(x, y, color.fromargb(255, myred, mygreen, myblue));             }          // assign new bitmap picturebox         picturebox4.image = (bitmap)bmp;         picturebox4.refresh();      }  

picturebox4.image works fine. picturebox4.refresh() triggers incorrect error. picturebox4 is being used on form created on.

what causing error trigger? using picturebox4.refresh() in other areas of code works fine.

by way, i'm been away code bit, plan on updating use lockbits.

thank

you trying update ui in non-ui thread. can dismiss exception using below code change picturebox4.refresh() or other similar access code sth below:

picturebox4.invokeifrequired(() => {     // want control here     picturebox4.refresh();     });  

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -