Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2016-04-23 22:17:51, last edited by gaberilde (2016-04-23 22:18:16)

gaberilde
Member
Joined: 2015-03-01
Posts: 25

Cant access any object in the playerio void

I cant access any object inside the void OnMessage(object sender, PlayerIOClient.Message m)
I can access all objects fine if the code is not in it.
this does not happen with if's

if (button_name.Text == "hi")

it only happens if you try to set any of the object proprieties.
example:

button_name.Text = "anything";

If you do that like i said this will exception will happen:

Exception thrown: 'System.InvalidOperationException' in System.Windows.Forms.dll

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

If there is a handler for this exception, the program may be safely continued.

Offline

#2 2016-04-23 22:19:07, last edited by ewoke (2016-04-23 22:20:48)

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: Cant access any object in the playerio void

what exactly are you trying to do

after actually reading, you cant cross thread that way, you have to invoke to change controlls

dirty fix = checkForIllegalCrossthreads = false;//can contain typos


if you can read this....good for you

Offline

#3 2016-04-23 22:26:34

gaberilde
Member
Joined: 2015-03-01
Posts: 25

Re: Cant access any object in the playerio void

is the void OnMessage(object sender, PlayerIOClient.Message m) accutly on a diffrent thread to say private void buttonlolao_Click(object sender, EventArgs e)  ?
if so how can i make them on the same thread?

ewoke wrote:

what exactly are you trying to do

after actually reading, you cant cross thread that way, you have to invoke to change controlls

dirty fix = checkForIllegalCrossthreads = false;//can contain typos

Offline

#4 2016-04-23 22:30:15

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: Cant access any object in the playerio void

a quick and dirty fix for this is to:

CheckForIllegalCrossThreadCalls = false;
in the constructor

if you can read this....good for you

Offline

#5 2016-04-23 23:47:46

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: Cant access any object in the playerio void

pls no make it right

button_name.Invoke((MethodInvoker) (() => button_name.Text = "hi"));

Offline

Wooted by:

#6 2016-04-24 00:03:26

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: Cant access any object in the playerio void

ninjasupeatsninja wrote:

pls no make it right

button_name.Invoke((MethodInvoker) (() => button_name.Text = "hi"));

Wouldn't you have to do this for every control you're trying to change? That's kind of annoying


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

Wooted by:

#7 2016-04-24 00:07:09

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: Cant access any object in the playerio void

Xfrogman43 wrote:
ninjasupeatsninja wrote:

pls no make it right

button_name.Invoke((MethodInvoker) (() => button_name.Text = "hi"));

Wouldn't you have to do this for every control you're trying to change? That's kind of annoying

moar propers

Offline

#8 2016-04-24 11:22:29, last edited by den3107 (2016-04-24 11:23:05)

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Cant access any object in the playerio void

Method that I like to use:

MethodInvoker mi = delegate
{
     // Do GUI stuff here
};
if (InvokeRequired)
{
     BeginInvoke(mi);
}
else
{
     mi.Invoke();
}

Until you learn what exactly invoking is and what delegates are, just use this. You don't have to know what it does, just copy paste it and replace the comment with the GUI stuff.

Multithreading is a b*tch, and sadly you can't really get around it with EE bots, hence why I personally don't think that EE bots are a good place to start learning C#, since you'll just learn yourself ugly quick methods you found on the internet, and will eventually think they're good not-ugly methods of doing so.
But let's not discuss that, there're already a couple dozen other threads where that happened.

Offline

den31071461493349598134

Board footer

Powered by FluxBB

[ Started around 1713598263.2552 - Generated in 0.037 seconds, 12 queries executed - Memory usage: 1.46 MiB (Peak: 1.59 MiB) ]