Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Visual C# Having a cross-thread error

c# is a buttmunch anddoesntwanttowork

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1 Toxicshadow

Toxicshadow

    CC Regular

  • Member
  • PipPipPip
  • 42 posts

Posted 10 August 2013 - 08:23 PM

Am trying to work on a very simple project, it's really just a timer that changes a radio button after an interval; unfortunately MSVC says 'lolnope' and is deciding to give me a cross thread error.  This is my full code for the main class, and in the OnTimedEvent() method is where I'm getting the cross-thread issue. Which is where I'm confused, as the button1_click() does not give a cross thread, but the timer event does. How to fix it?

 

Edit: Nevermind. I'm sorry for the spam. After like 30 mins of frustration, I came and posted here. 5 Mins later, I found my answer here.
Again, sorry.

-snip-

Edited by Toxicshadow, 10 August 2013 - 08:36 PM.


#2 AceInfinity

AceInfinity

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 313 posts

Posted 11 August 2013 - 09:02 PM

You shouldn't be using anything other than the Windows.Forms.Timer anyways. *All* other timers are run on system managed threadpools, and in that case you have to invoke the UI thread everytime anyways to do anything.

Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image


#3 BlackDoom

BlackDoom

    CC Regular

  • Member
  • PipPipPip
  • 45 posts

Posted 13 August 2013 - 09:09 AM

you can always disable the check for cross threading, that usually solves most of the problems regarding cross threading issues in .NET you do it like this in the fourm load function:

 

    CheckForIllegalCrossThreadCalls = false;

and yes the property is really called "CheckForIllegalCrossThreadCalls" LOL



#4 AceInfinity

AceInfinity

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 313 posts

Posted 13 August 2013 - 11:53 AM

you can always disable the check for cross threading, that usually solves most of the problems regarding cross threading issues in .NET you do it like this in the fourm load function:

 

    CheckForIllegalCrossThreadCalls = false;
and yes the property is really called "CheckForIllegalCrossThreadCalls" LOL


It should never be used though for a released product. You should read the MSDN documentation on that property... The proper way is to invoke.

Edited by AceInfinity, 13 August 2013 - 11:53 AM.

Microsoft MVP (2012) - .NET Programming | ®Crestron DMC-T Certified Programmer
Posted Image


#5 BlackDoom

BlackDoom

    CC Regular

  • Member
  • PipPipPip
  • 45 posts

Posted 14 August 2013 - 06:25 AM

It should never be used though for a released product. You should read the MSDN documentation on that property... The proper way is to invoke.

 

I know I know, sorry I didn't mention it but I just wanted him to have a quick fix :(






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download