locked
Wpf app - thread exit issue? RRS feed

  • Question

  • Hi,

    I am working with wpf app and facing the below thread exit issue. Please see the code and suggest if any correction needed.

    The thread '<No Name>' (0x12d0) has exited with code 0 (0x0).

    The thread '<No Name>' (0x9f0) has exited with code 0 (0x0).

    private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                try
                {
                    // Create a sample listener and controller
                    LeapListener listener = new LeapListener();
                    Controller controller = new Controller();
                    listener.OnInitEvent += new EventHandler<LeapInfo>(listener_OnInitEvent);
                    listener.OnConnectEvent += new EventHandler<LeapInfo>(listener_OnConnectEvent);
                    listener.OnDisconnectEvent += new EventHandler<LeapInfo>(listener_OnDisconnectEvent);
                    listener.OnExitEvent += new EventHandler<LeapInfo>(listener_OnExitEvent);
                    listener.OnFrameEvent += new EventHandler<LeapInfo>(listener_OnFrameEvent);
                    // Have the sample listener receive events from the controller
                    controller.AddListener(listener);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            private void listener_OnInitEvent(object sender, LeapInfo e)
            {
                //listBox1.Items.Add(e.Init);
                Dispatcher.BeginInvoke(new Action(() => {
                listBox1.Items.Add(e.Init);
                }));
            }
            private void listener_OnConnectEvent(object sender, LeapInfo e)
            {
                //listBox1.Items.Add(e.Connect);
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    listBox1.Items.Add(e.Connect);
                }));
            }
            private void listener_OnDisconnectEvent(object sender, LeapInfo e)
            {
                //listBox1.Items.Add(e.Disconnect);
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    listBox1.Items.Add(e.Disconnect);
                }));
            }
            private void listener_OnExitEvent(object sender, LeapInfo e)
            {
                //listBox1.Items.Add(e.Exit);
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    listBox1.Items.Add(e.Exit);
                }));
            }
            private void listener_OnFrameEvent(object sender, LeapInfo e)
            {
                string strFrameData = "Frame Id: " + e.FrameId.ToString() +
                                   " FrameTimestamp: " + e.FrameTimestamp.ToString() +
                                   " FrameHand count: " + e.FrameHandCount.ToString() +
                                   " FrameFingercount: " + e.FrameFingerCount.ToString() +
                                   " FrameToolcount: " + e.FrameToolCount.ToString();
                //listBox1.Items.Add(strFrameData);
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    listBox1.Items.Add(strFrameData);
                }));
            }
    class LeapListener : Listener
        {
            
            public event EventHandler<LeapInfo> OnInitEvent;
            public event EventHandler<LeapInfo> OnConnectEvent;
            public event EventHandler<LeapInfo> OnDisconnectEvent;
            public event EventHandler<LeapInfo> OnExitEvent;
            public event EventHandler<LeapInfo> OnFrameEvent;
            public override void OnInit(Controller controller)
            {
                //Debug.WriteLine("Initialized");
                if(OnInitEvent == null)
                    return;
                var leapInfo = new LeapInfo();
                leapInfo.Init = "Initialized";
                if(OnInitEvent != null)
                    OnInitEvent(new object(),leapInfo);
                    
            }
            public override void OnConnect(Controller controller)
            {
                //Debug.WriteLine("Connected");
                if (OnConnectEvent == null)
                    return;
                var leapInfo = new LeapInfo();
                leapInfo.Connect = "Connected";
                if (OnConnectEvent != null)
                    OnConnectEvent(new object(), leapInfo);
            }
            public override void OnDisconnect(Controller controller)
            {
                //Debug.WriteLine("Disconnected");
                if (OnDisconnectEvent == null)
                    return;
                var leapInfo = new LeapInfo();
                leapInfo.Connect = "Disconnected";
                if (OnDisconnectEvent != null)
                    OnDisconnectEvent(new object(), leapInfo);
            }
            public override void OnExit(Controller controller)
            {
                //Debug.WriteLine("Exited");
                if (OnExitEvent == null)
                    return;
                var leapInfo = new LeapInfo();
                leapInfo.Exit = "Exited";
                if (OnExitEvent != null)
                    OnExitEvent(new object(), leapInfo);
            }
            public override void OnFrame(Controller controller)
            {
                if (OnFrameEvent == null)
                    return;
                // Get the most recent frame and report some basic information
                Frame frame = controller.Frame();
                HandList hands = frame.Hands;
                int numHands = hands.Count;
                //Debug.WriteLine("Frame id: " + frame.Id
                //            + ", timestamp: " + frame.Timestamp
                //            + ", hands: " + numHands
                //            + ", fingers: " + frame.Fingers.Count
                //            + ", tools: " + frame.Tools.Count);
                var leapInfo = new LeapInfo();
                leapInfo.FrameId = frame.Id;
                leapInfo.FrameTimestamp = frame.Timestamp;
                leapInfo.FrameHandCount = numHands;
                leapInfo.FrameFingerCount = frame.Fingers.Count;
                leapInfo.FrameToolCount = frame.Tools.Count;
                if (OnFrameEvent != null)
                    OnFrameEvent(new object(), leapInfo);
                }
            }
     public class LeapInfo : EventArgs
        {
            public string Init { get; set; }
            public string Connect { get; set; }
            public string Disconnect { get; set; }
            public string Exit { get; set; }
            public long FrameId { get; set; }
            public long FrameTimestamp { get; set; }
            public int FrameHandCount { get; set; }
            public int FrameFingerCount { get; set; }
            public int FrameToolCount { get; set; }
        }



    Thursday, January 3, 2013 12:14 PM

Answers

All replies

  • Hi ykbharat,

    I have not found the incorrect part in your code, could you tell me your basic needs, what is your goal, might I could help you achieve your goal by a WPF build in approach.

    best regards,


    Sheldon _Xiao
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 7, 2013 9:00 AM
  • Hi Sheldon _Xiao,

    Thanks for the reply. My goal is to access the OnFrame() method info (frame, hands, fingers data) and make use of the data in WPF Window (as displayed in main Window Listbox).

    Here is a short notes of the Leap API which I used and Please suggest an effective approach for accessing this API in WPF.

    The Controller class provides the main interface between the Leap and your application. When you create a Controller object, it connects to the Leap software running on the computer and makes hand tracking data available through Frame objects. You can access these Frame objects by instantiating a Controller object and calling the Controller.Frame() method.

    If your application has a natural update loop or frame rate, then you can call Controller.Frame() as part of this update. Otherwise, you can add a listener to the controller object. The controller object invokes the callback functions defined in your Listener subclass whenever a new frame of tracking data is available (and also for a few other Leap events).

    • Edited by ykbharat Tuesday, January 8, 2013 10:12 AM content edited
    Tuesday, January 8, 2013 10:10 AM
  • Hi ykbharat,

    As far as I know, this "LeapListener " class is not created by micrsolft, if what I said is correct, if so, I think it is not a WPF issue, I suggest you post it on C# forum to get better support, the link is:

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/threads

    Best regards,


    Sheldon _Xiao
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by ykbharat Tuesday, February 5, 2013 4:49 AM
    Thursday, January 10, 2013 3:19 AM