1 Replies - 1024 Views - Last Post: 12 October 2012 - 06:39 PM Rate Topic: -----

#1 TomTheBeast   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-October 12

Cross-Thread If statement

Posted 12 October 2012 - 05:54 PM

Hey, well I've ran into a problem; which is probably a simple fix.
I have a thread running in the background checking things, etc.
The output is this:
Cross-thread operation not valid: Control 'comboBox1' accessed from a thread other than the thread it was created on.

The code is:
if (comboBox1.Text != "")
                if (Race != comboBox1.Text) { return; }

Obviously, ComboBox1 wasn't created on the thread I'm running the check on, is there anyway I can check ComboBox1's text across threads?
Note: This is on 7 different occasions, occurring with 5 ComboBox's, 1 TextBox, and a ListView.
Note 2: I've been told that I need to invoke my form, how would I go about doing this? I've never even heard of invoking a entire form.

Is This A Good Question/Topic? 0
  • +

Replies To: Cross-Thread If statement

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6534
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Cross-Thread If statement

Posted 12 October 2012 - 06:39 PM

I think you have more of a design issue going than you think.
You should NOT be polling at all. Why do you need a thread checking the state of things? Those things will raise an event when they change. That's what you care about. Instead of polling the status of the combobox, react to the .SelectedItemChanged event.

This post has been edited by tlhIn`toq: 12 October 2012 - 06:40 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1