0

I am trying to use Threads in my app but i get a error. I searched a solution at MSDN and other forums but i didn't get it.

public class ClickingThread
    {
        private const int MOUSEEVENTF_LEFTDOWN = 0x0002;
        private const int MOUSEEVENTF_LEFTUP = 0x0004;

        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

        public ClickingThread() 
        {
        }

        public void MouseClicking()
        {
            int X = Cursor.Position.X;
            int Y = Cursor.Position.Y;
            Thread.Sleep(100);
            mouse_event(MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0);
        }

        public void Click()
        {
            while (true)
            {
                MouseClicking();
            }
        }
    }

And when i try to use method from this class like this

ClickingThread clicker = new ClickingThread();
Thread click = new Thread(new ThreadStart(clicker.Click));

I get an error (second line -> clicker.Click)"A field initializer cannot reference the non-static field, method etc."

Thanks for advices.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
mikroice90
  • 137
  • 1
  • 9

0 Answers0