none
How to make two functions run concurrently? RRS feed

  • Question

  • I have two functions that are called like within start():
    SpawnIterator(this.Readkinect);
    SpawnIterator(this.Explore);

    The structures of these two functions are:
    private IEnumerator<ITask>ReadKinect()
    {
        while(true)
        {
            ----
            yield return TimePort(1000).Receive();

        }
    }

    public IEnumerator<ITask>Explore()
    {
        while(true)
        {
            ----
            yield return TimePort(1500).Receive();

        }
    }

    I am trying to concurrently call two functions. But as I debugged, I noticed that ReadKinect() is calls first, some statements of its are executed, then Explore are called, next while statement of Explore() is called repeatedly, but control never goes to ReadKinect().

    Pls suggest me where I made wrong.
    Thank you

    Sunday, December 15, 2013 8:56 AM

Answers

  • Hello,

    I'm not sure if your use of 'while' is somehow contending with the scheduling of tasks by the DispatcherQueue.

    Here's a stab in the dark... rather than using a 'while' loop, could you try using an 'if' statement with a condition that checks a class level variable?  Upon satisfaction of said condition, then just spawn another invocation of your ReadKinect or Explore methods; respectively.  One nice thing about this 'if' approach is the ability to cleanly shut down your looping mechanism via an external member.

    Thanks,


    Dennis M. Knippel

    Monday, December 16, 2013 10:34 PM
    Moderator