0

So I need to store the information from:

this.PointToClient(Cursor.Position).ToString());

but when I try to do:

var variable = this.PointToClient(Cursor.Position).ToString());

it gives me

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

I know how to get this numbers using

cursor_pos.Invoke(() => cursor_pos.Text = this.PointToClient(Cursor.Position).ToString())

But in that way I can't store them or change them. What do i need to do in that case?

Thank you!

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
J.COKS
  • 11
  • 2
  • Read some examples, and you might gain some insights, https://halfblood.pro/how-to-replace-backgroundworker-with-async-await-and-tasks-80d7c8ed89dc – Lex Li Jul 02 '22 at 20:07
  • Why would you need to Invoke anything? Did you use the wrong Timer? Did you start a Thread just to get the current cursor position? Other? Post the code that shows what you're doing there. -- In case you actually need to invoke, note that `Invoke()` returns an `object`. – Jimi Jul 02 '22 at 20:08
  • I mean, you write something like: `var p = (Point)Invoke(new Func(() => PointToClient(Cursor.Position)));`. But you shouldn't need any of this. – Jimi Jul 02 '22 at 20:16

0 Answers0