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.
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
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
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?
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
a quick and dirty fix for this is to:
CheckForIllegalCrossThreadCalls = false;
in the constructor
if you can read this....good for you
Offline
pls no make it right
button_name.Invoke((MethodInvoker) (() => button_name.Text = "hi"));
Offline
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
thanks zoey aaaaaaaaaaaand thanks latif for the avatar
Offline
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
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
[ Started around 1732751493.1273 - Generated in 0.165 seconds, 14 queries executed - Memory usage: 1.47 MiB (Peak: 1.6 MiB) ]