KinectSDK poll after using events - c#

I have two sections of a Kinect app I'm making. There's a WPF menu which eventually directs the user to an XNA Game.
The problem is the WPF controls I'm using (like KinectRegion) are adding event listeners to things like AllFramesReady on the KinectSensor object. And as soon as I try to poll for skeleton data in my XNA game, I get the following error:
This API cannot be called when an event listener has been set
My question: How can I reset everything in the KinectSDK so I have a clean slate when starting my XNA game? Or at the very least, get it into a state where I can poll for skeleton data successfully.
I don't know what methods the WPF controls are attaching to handle the events, so I can't explicitly remove them from the event.
Similar issue: Get color Image not in the frame ready event

You are not able to use event handler and polling method at one time. Kinect API won't support that. better way is to use global variable for your polling method and use it on anywhere that you want.

Related

Xamarin.Android. Setting time for LongClick event

Is it possible in Xamarin.Android to set event LongClick click time or something similar? The click time as it is, is too short for me.
LongClick timing is managed by the Android OS, so it cannot be directly modified. However, you could go around the problem by handling everything by yourself.
Create a touch listener.
In the OnTouch event, detect if the touch action is MotionEventActions.Down and get the current time in milliseconds by using CurrentTimeMillis method.
Have another check for MotionEventActions.Up to detect when the user lifts the finger. Calculate the time difference between touch up and touch down events and if it's long enough, do something.
Here's some code samples related to touch events. It shows how to create the touch listener and react to touch events.

Add a c# canvas to an MVC view?

Is there a way to add a canvas (or anything that can render a c# application, more specifically a game such as Tetris) to an MVC view?
I would like to make a game, add it to a view, and send the score of the client to the server to process rewards and other stuff.
I have no idea how to get started, can someone show me the way please?
I would prefer to not use JavaScript for this, I would like a server based application.
Sorry, but you're going to need to use JavaScript since the API for canvas is written in it.
Another issue you're having, I think is you data layering. Which will eventually look like this:
C# Server <- Javascript Events -> Canvas View
Basically Javascript will call async methods to your server every so often, either getting data (current high scores) or sending data (giving new scores). In turn it will update the canvas view. Also, everything that happens to the canvas will be handled in JavaScript through its event handling system. These event handles can trigger other events like calls to the server or a local event like the current falling block to rotate.
I don't see away around JavaScript being a huge part of this, since you can't really do a real time game without a lot of it being client side, at least in a web based game.

How to trigger same event on every page of the WPF App using MVVM Light

Our application is implemented in WPF using MVVM Light.
We are replacing our old magnetic card reader which is currently a serial one with a USB HID-KB.
Serial card reader were easy since we had serial port events to trigger the incoming messages, we had no problem in handling these. But with USB card reader, the events are that of a normal keyboard. By the way, the card reader does not have vendor specific API, this a generic USB device.
As of now the solution is to capture a keydownevent in the view and handle the business logic on the viewmodel.
But the problem here is that the end user can swipe the card irrespective on whatever page he/she is on. We should be able to capture that swipe event. The only option I currently have is that I need to wire this keydownevent on every view as mentioned above.
Is there any way in MVVMLight or WPF that can declare an event on the global level, that can be triggered from every view.
Any pointers will be highly appreciated.
Thanks,
The solution is very simple.
Why don’t you handle the event in a common file, like the base file. Normally we handle application close events in such base files which will always be active. The thing is I have some conditions to check while the application is closing. So I handle the event in the common base file and do the condition checking there.
Please try that and let me know the result..

How to efficiently react to touch events in Windows RT

This might be a dumb question but I'm not familiar with XAML.
I'm implementing a RTP-MIDI client Library for Windows Store Apps and would like to investigate and troubleshoot potential latency and performance problems.
I've written a quick dummy application with a couple of buttons to send MIDI events to an musical instrument over the network using my Library. In that scenario, I find that my Library is able to process a single basic MIDI event in under 10ms over the network, but I find that the delay between the time I press a button on the UI and the time where my Library is instructed to send an event is very high.
Ideally, I would like to react to a "touch pressed" event and instantly send a MIDI event as well as a "touch released" event and instantly send the corresponding MIDI event.
I could not find such events on the regular button controls. Ideally, I would like to achieve the highest performance possible from the UI, even with a single button, in order to eliminate this source of problems in my performance assessment.
Is there a way I could react to the screen being touched "in real time" like a game, for instance?
The most basic access to various pointer events (such as tapping, clicking) are available through a series of lower level events, with these being directly related to your question:
PointerPressed
PointerReleased
PointerPressed should be the equivalent of MouseDown for example in a traditional application as it fires early, and before any translation into a higher level event (such as Click) has occurred.
The PointerReleased would be the equivalent of MouseUp. If you're relying on the PointerReleased event, you'll want to take note of the fact that the event isn't necessarily fired as a pair with the PointerPressed event, as there are a number of conditions where it may not fire. The documentation has the details.

Silverlight/WP7 - Navigation and events triggering on other pages

My basic issue is this, I have events firing on pages I've left based on network activity that are causing problems when I thought the old forms were being destroyed.
More detailed information: I am writing a windows phone app that communicates with a network player. I have a static instance of my communication class in my App class so all the forms can share the connection, and all my forms subscribe to it and process results within that form. From a main menu you can choose one type of source and it opens a file browsing form that refreshes a listbox as you navigate, cancels the back button and refreshes the new contents to simulate file navigation until you are the root folder. The app doesn't know if you're clicking on a file or folder, it gets a network message when media starts playing and watch for that and then navigate to a "play" form. I had been using all .Navigate's for this until now and it worked great until I added another branch off the main menu for a new source. Although the new source is completely different, the device sends a lot of the same generic commands which just mean something else in the current context. After visiting the my file browser form and going to my new source, a play command from the network, which means something else now, would cause my to jump into my old "play" form from the previous source as if I was still on the file browser form, which isn't intended.
So I've tried many things and have it kind of working now but it's message and I lose some features. Currently I changed from using all .navigates, also in the back button override, to trying to use the stack and navigate.goback's. I pass variables when needed using globals in App and unhook my net listeners from the form, goback, and then connect them in the new form's listeners in it' navigatedto. I think there is timing issue though as in some cases I needed to send a command to the media box as it's changing and it ended up triggering the wrong event handler again. I think the easiest solution, if possible, and they way I though it would work is if each time I navigated from the form it old one, it's handlers, etc were all destroyed and I didn't have to use the stack at all, handling all the back buttons myself.
I know that's a long description and thanks if you made it this far, hopefully it made some kind of sense. Does anyone have any suggestions on what I can do?
As a side note I'm a long time self-taught VB programmer who has been stuck in .net 2.0/winforms and I've just now made the move to C#, OOPs, and XAML to write my first Windows Phone app so it's likely I'm doing something stupid or overlooking something obvious...
It is likely because something has retained reference to the form. The most common cause is event handlers.
So, if your static class exposes an event, and you subscribe to that event in a form, you must unsubscribe from the event when your form closes / navigates, otherwise the form will remain in memory....
If that isn't the case, look for something else that is acquiring a reference to your form and not releasing it.
Most likely the problem is based on a bad application architecture, when it comes to handling commands send from the UI.
When you say 'sends a lot of the same generic commands which just mean something else in the current context.' you most likely reveal the source of the problem.
As a workaround, you can define an interface, that your communication class implements. Each form has it's own method it calls on a communication class instance.
If you indeed receive a command from a phone page, that is no longer in view, just don't process it.
You can store the navigation history to always know what page is the only one allowed to send commands to a communication class.

Categories

Resources