Windows 10 uwp sticky background service? - c#

I'm trying to convert an Android app to Windows 10 UWP. On android its easy: when boot completed, app service is started. It connects to controller over internet, fetches system state and all data (temp sensors, pumps, valves, etc) and keeps everything in memory. Foreground app can get data as soon as service gets them and display values, charts realtime. After closing foreground app, service keeps working, I still have all system state and I can play alarm sound if needed.
Is it possible to do [almost] same functionality on Windows 10 uwp?
I cannot find a way to start service with windows. Service started with foreground app is stopped when foreground app is closed. SocketBackgroundTask keeps connection perfect, but system state is lost with service.
Should I save system state to file and analyze all data after each renew? Data flow varies from once in 10 minutes to ~10 per second.
Or should I forget Windows 10 as limited platform?

I am designing a similar piece of sensor control software, and I have found UWP/Win10 to be limiting. We ultimately resorted to using Assigned Access to keep the app permanently in the foreground.
Assigned Access
Assigned access assigns an app to an account. So when Mr. Bob logs in, the app starts full-screen, and it cannot be closed, and if it crashes, it is restarted.
Note that the only way to access other parts of the system is to hit ALT-CTRL-DEL and log in as a different user. That might be bad for some, but if you have critical process monitoring going on, then it's probably a good thing that the user can't mess about with the system or quit the app.
It's also quite simple to implement, you only need to add a declaration to the app manifest, and you need Win10 Pro or Higher.
Windows IoT
You could also look at Windows 10 IoT, when you deploy an app to it, it does pretty much the same thing. However the range of hardware is quite limited, and many of them aren't fully functional yet - RPi suffers from SDcards being inherently unreliable, and lack of graphics acceleration. Dragonboard lacks driver support for resolutions other than 720p, etc. https://developer.qualcomm.com/forum/qdn-forums/hardware/iot-development-platform/29652
Extended Execution
In addition we have experimented with using extended execution, which lets the app run in minimised state, potentially indefinitely. I have mixed feelings about it. Although the app will keep running most of the time, but if the OS is struggling for resources, the app will get suspended and won't be restarted until the user switches back to it.

Related

Xamarin Android - Periodic task execution

I'm writing an app with Xamarin.Android to retrieve data from some domotic sensors(Sonoff, Shelly) and to set some switches. I need it to make api calls even in background, say about every 5 or 10 minutes. I know it's a very short amount of time, I plan to do this with an Arduino later, but now I need this.
I researched a bit, read about Services and their limitations, but I can't figure out how to do this. Can someone help me? Thanks
You can either:
create a Foreground Service that keeps running, and you execute a timer there
use WorkManager from Android X, which depending on device capabilities and software versions will use the following in priority:
JobScheduler
Firebase JobDispatcher
AlarmManager
JobScheduler allows you (kind of like cron on Linux) to set up scheduled tasks to be run. However, it is limited in how frequent you can do this. This frequency depends on Android version and depends on the criteria on the job and whether the device is not running out of resources.
With the foreground service, you can do more or less what you want as long as the service is alive. You might need to disable battery optimizations in battery settings for your App, but otherwise it should just work.
Apart from these features, unless you are either using a rooted device or you are device admin on the device, you can't do much more. In case of root/device admin, you can mark your app as Persistent to disallow it being killed by Android.

Debugging by attaching a process for windows phone apps

I'm currently running VS2013 Update 3, I'm building an app and i;m trying to mimic the Rate My App that shows up rate message dialog in b/w specified intervals.
My problem is that i've made a setting using ApplicationData.current.loclasettings and it is an integer.
and i want to see the settings number being updated every time i close and run the app to ensure the logic is perfect.
but i'm unable to do it. Every time i deploy the app from vs it replace the original app and thus erasing all the settings that have been previously saved.
I've tried to use attach a process but it doesnt work on windowsphones.
Well after a bit of research and going through the documentation it is clear that there is no way you can attach a process to the app that is already running on the phone.
At least for me there was no other way because Microsoft kept the USB debugging thing a little bit undocumented or not documented at all.
So, who ever are looking forward to first launch the app on a connected windows phone and then start the the connect to a process and select the appropriate device for communication , story it is not possible, at least the build that i;m using doesn't support. may there might be a better solution in the future.

Programmatically communicate with multiple unfocused VMWare instances with C#

Even though my long title spoils quite a lot of my question, I'll try to be more specific here.
I have 5 VMWare instances that all have their own tasks to do. They are hosted on one same computer. But I need one program (that I'm actually writing, duh) to get informations and to send informations such as keystrokes and mouse clicks. But from what I've red so far, communication between programs is quite hard to achieve and I haven't found any way to send keystrokes to an unfocused or reduced VMWare windows. Plus I would need to send different and specific keystrokes to each of my 5 VMWare instances.
My program will starts itself each 5 tasks in each 5 windows. The order doesn't matter as long as each instances have its own tasklist. I would need a way to keep track on each window's identity so I don't send let's say window 4's keystrokes to window 5. I would also need to be able to check periodically if each VMWare's instances is doing its job. Additionnaly my VMWare's instances are all running in a win7 environnement.
Now that the whole situation is explained, I'll sum up the question I'm currently submitting. Is there any way for my C# program to keep track of 5 VMWare's instances' identities and both send keystrokes (+ mouseclicks) and get at least screenshots of what's displayed on each of them even though they are reduced or unfocused ?
Thanks a lot.
Is there a way to get
You have an incorrect understanding of how VMWare works. VMWare isn't "running in a window". VMWare is running in a virtual machine at a very low level in your computer. What you see as a "window" is merely a "viewer" that allows you to connect to the remote machine (even though it's running on the local computer). This "viewer" is an application similar to the remote desktop client, or a VNC client. As such, there is very limited interaction between the OS and the host OS and the applications running in the guests.
This means that your host OS doesn't know anything about the individual applications running inside the guest OS, and you can't see it's window handles, or control mouse or keyboard events. In fact, the VMWare drivers "capture" the hardware and steal these events directly from the hardware, so there is no real way for your application to simulate a human interacting with the Virtual machine window.
What you COULD do, and this would be a lot of work, is create "agents" on each of the virtual machines that would have access to the applications running on them. These agents could listen for events on the network, and you could send events to them to do what you want. However, as I said.. this is likely a lot of work.
This whole thing sounds kind of cheesy to begin with, like you're trying to do something the hard way, but since you haven't told us what you're ACTUALLY trying to do.. we can't suggest any better alternatives.
A quick and dirty approach is to look into Visual Studio Test Controller and Agents. The idea is to install the agent on each one of the machines. You can then leverage the MSTest framework (wrongly called unit tests) to execute you c# code one each agent.

Listening to "Triggers" and reacting to them in Windows Phone

There are apps on Android such as Tasker and Trigger that allows the user to set up some "Triggers" and the "Responses" that should execute when each trigger triggers.
The triggers could be, for instance: Connecting to a certain Wi-Fi, Arriving a certain location (Geo-Fencing), Plugging the earphone, tapping an NFC Tag and so forth.
I wonder if there's any way to to something like this on the Windows Phone platform. I have no background in developing for WPhones (even though i have a huge C# background), so i'm not sure whether the platform itself allows this sort of "background monitoring of sensors or, if there are such sensors (such as "headphone plug").
After a quick research, seems that access to some APIs are not allowed from Background Threads, i wonder if there's anything related to security here, or just an inability of the platform.
Is there any way to achieve what i want?
On Windows Phone 8 you can perform background processing, with Background Agents.
You can use Sceduled Taksto register a class containing a method that is called periodically, even when your app is not running. They are multipurpose and offer the greatest utility for extending your app to perform background activities.
You can surely display a message to the user, or fire an alarm or something, a message would be more suited, for location aware apps. Those registered as geographic location providers are able to continue running despite there being another app running in the foreground.
For the rest of your triggers, I'm not sure. You'll have to check the Sensors.
No, you can't hook any triggers or events. The only thing you can, as Pantelis said, is to create very limited PeriodicTask that may or may not be run every roughly 30 minutes and be constrained to max 25s of running time. This is deliberate platform limitation, AFAIK done mostly because of battery usage and security reasons.
If something can't be achieved by PeriodicTask, give it up. This is the most versatile background process, others are even more limited. This is by design to prevent daemons from taking over the phone.

Minimize Windows 8 Store App while tracking location with GPS

I'm working on a metro app and am having trouble finding how not to show the application.
We recently deployed tablets to our field reps, and need to add gps tracking. GPS is much easier to deal with in the metro libs (it's like 4 lines of code vs. unmanaged) so we're hoping to be able to push a metro app instead of spending time coding a winforms/wpf desktop app (the tablets are full version windows, so it's an option if we can't hide a metro app. I feel like it should be possible though as the start screen tiles update automatically without opening the main program).
In WPF, it's fairly simple to make a window invisible. I'm creating the metro app in wpf, but it uses different libs than desktop and I may just not know how to do it.
In desktop programs, it's fairly simple. You do something along the lines of:
<Page
x:Class = xxxxxxxx
..
Visibility="Hidden">
Unfortunately, with metro, the only options I have are collapsed and visible. Collapsed doesn't seem to have any effect, unless it's just because it's not deployed and visual studio shows it anyway...
So basically I'm trying to figure out if there's a way to start the program minimized or hidden so that it doesn't interrupt the field reps every time it takes their location.
If you really want to make a metro app and want it to run "minimised" you will need to look at background task. To start the background task the user would still need to start the app at least once, futhermore background task have limitation how how often and how long they can run. Also there is a lot of constraint on deploying a windows store app if you cannot publish it in the store.
If your goal is to just have access to GPS through C# apis, the GPS is actually one of the winRT api you can use from the desktop, you can find a tutorial on how to access winRT api from the desktop here
Here is the complete list of winRT api accessible from the desktop (You can find Geoposition class among them).
Have you looked into creating a background task that transmits GPS? The background task can run without the app running.
I am not entirely certain you can voluntarily minimize a Windows Store App on a user's behalf. I see nothing in IntelliSense about it, nor have I found anything online or see any app do it.
However, be aware that deploying the app without using the Windows Store -- sideloading -- requires Windows 8 Enterprise edition computers joined to the domain OR Windows 8 Pro with a sideloading key ($30 per key, purchased in packs of at least 100.) Perhaps a WPF app with unmanaged code is worth the money and effort.

Categories

Resources