0

My application plot values from an electronic device. It plots 10 values in one second. It waits for 100ms before fetching the next value. The waiting is given by Thread.Sleep(100); This much part is working fine.

I am showing the mouse position in MouseMove event. But to show the position it takes a delay which i have given before.

So i want to avoid that delay. I tried to run the MouseMove event in thread like new Thread(chartControl1_MouseMove).Start();. But it gives the following errors:

  1. The best overloaded method match for 'System.Threading.Thread.Thread(System.Threading.ThreadStart)' has some invalid arguments.
  2. Argument '1': cannot convert from 'method group' to 'System.Threading.ThreadStart'

Any suggestions...???

Ravishankar N
  • 141
  • 1
  • 1
  • 9
  • What do you mean by "I am showing the mouse position" ? Does this mean you are fetching the mouse position and plotting this into your chart? – yas4891 Aug 10 '11 at 06:45
  • Similar question, same error (see comments), same solution: http://stackoverflow.com/questions/5155979/c-thread-method – Abel Aug 10 '11 at 07:29

4 Answers4

0

MouseMove event takes some arguments. But the thread start isnt passing them. its assuming that the method has void params.

Zenwalker
  • 1,883
  • 1
  • 14
  • 27
0

This is because your method chartControl1_MouseMove which I take is declared as

public void chartControl1_MouseMove(object sender,MouseEventArgs e)

can not be converted to to a ThreadStart delegate which takes the form of

public delegate void ThreadStart()

to make this work you will need to create a method of its own with void return type and no parameters like

private void foo()

and change your line of code to:

new Thread(foo).Start();

That way it should at least compile. You then have to implement the desired behaviour inside the foo method.

yas4891
  • 4,774
  • 3
  • 34
  • 55
0

You are using a method that requires parameters. Either change the method to have no parameters, or use a worker item:

ThreadPool.QueueUserWorkItem(o => Method(m));

You need to convert your method chartControl1_MouseMove(object sender, MouseEventArgs e) to something that contains one argument, or you can revert to using Tasks instead. In general, it's often better to place your working code in its own method and let the event be the event (which is already called asynchronously if in a form). Then you call the working method (queue it) from the event.

There are advantages of using a thread pool over threads, see this post.

Community
  • 1
  • 1
Abel
  • 56,041
  • 24
  • 146
  • 247
0

Use parameterizedThreadStart or better move the body of mouse_move handler to some other method and run that method on thread.

hungryMind
  • 6,931
  • 4
  • 29
  • 45