I have kind of problem with multithreading, below pseudo code:
{
float x,y,z;
get_coordinates_from_kinect()// put them into variables x,y,z
public void button1_Click(object sender, RoutedEventArgs e)
{
Thread thr = new Thread(DoStuffOnThread)
thr.Start()
}
private void DoStuffOnThread()
{
Dispatcher.Invoke(new Action(doSomething));
}
void doSomething()
}
I am getting coordinates from kinect constantly. I would like to use this data to proceed when I click button1, so I decided for multithreadnig, but the problem is when I'm pushing the button operation runs only once (one set of coordinates). I aiming to sending this data constantly. how to do this ? I'm doing my project in c# as wpf.
You need to create and start your thread in the constructor of your class (not in the click event handler). Then create a queue (or a list) to add your coordinates to. In the DoStuffOnThread() method you should continuously (in the loop) call get_coordinates_from_kinect() and add the set of set of x,y,z to the queue. Finally, in the event handler for button click, get the items from the queue and proccess them as needed
Here is the example: