Click here to Skip to main content
14,875,778 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HI. I downloaded this project; it compiles and runs fine. BUT when I try to run it in Debug, I get an error. Specifically, I can run to the point of opening a file but as soon as the file is opened I get this error:

Cross-thread operation not valid: Control 'SettingsGroupBox' accessed from a thread other than the thread it was created on.


private void ButtonState(bool state)
    SettingsGroupBox.Enabled = state;
    DisplayGroupBox.Enabled = state;
    writeCurrentToJpgToolStripMenuItem.Enabled = state;
    writeJpgToolStripMenuItem.Enabled = state;
    openToolStripMenuItem.Enabled = state;

specifically on any of the Enabled=state; lines (I tried commenting them out one by one.

As I am trying to learn how to create jpgs dynamically from arbitrary data, I would like to single step through the app. Any ideas? I am using MS Visual C# 2010 Express.


[no name] 5-Sep-12 11:08am

1 solution

THe problem is fairly easy to understand, but far more complicated to fix.

The code you downloaded was poorly written and possibly for an older version of the .NET Framework, like 1.x.

You cannot touch any forms or their controls from a seperate thread other than the one that created the forms/controls. Fixing that may involve restructuring the application code and adding code to marshal these control manipulations to the correct thread.

Read this[^] for the hows and whys.
RonNYC2 5-Sep-12 11:16am
Thank you. I sort of was leaning in that direction but of course hoping there was a simpler solution. Maybe I'll look for other jpg generating code. Again, THANKS!!!


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900