I'm planing to start a UWP application that monitor a sensor data for 365 days and save all data to database(Sqlite).
I still worry about UWP capability. Please advice me Which should I use (UWP/WPF) ? I want to use better UI, than, I want to use UWP if possible...
UWP-Suspending is my worry.
With this post, Some people said a way to prevent a UWP application from suspending..
var extendedExecutionSession = new ExtendedExecutionSession();
extendedExecutionSession.Reason = ExtendedExecutionReason.Unspecified;
var extendedExecutionResult = await extendedExecutionSession.RequestExtensionAsync();
if (extendedExecutionResult != ExtendedExecutionResult.Allowed)
{
//extended execution session revoked
extendedExecutionSession.Dispose();
extendedExecutionSession = null;
}
Question
If I wrote this code in UWP app, Can I use a UWP application like Desktop WPF application ? I want to run my UWP application for 365 days without stopping
.. even if user do "minimized" on desktop... Please advice it...
Yes, you can do that with ExtendedExecution. One thing to note is when you run on battery (e.g. laptop, tablet) you will get suspended after some time - however you can prevent that as well by going into the Battery settings page and set your app as "Always Allowed".
Details are documented here: https://learn.microsoft.com/en-us/windows/uwp/launch-resume/run-minimized-with-extended-execution
Related
I've built a WPF app in C# which needs to know the user's location, and currently requires that it be entered manually. I'm using the Desktop Bridge to make it be able to run as a UWP app. When it's running as a UWP app, I want to take advantage of the Windows 10 location API if it is enabled. I'm using the following code to request for location access when the program starts:
public static async void RequestAccess()
{
var accessStatus = await Windows.Devices.Geolocation.Geolocator.RequestAccessAsync();
switch (accessStatus)
{
case Windows.Devices.Geolocation.GeolocationAccessStatus.Allowed:
UwpDesktop.hasLocationAccess = true;
break;
case Windows.Devices.Geolocation.GeolocationAccessStatus.Denied:
UwpDesktop.hasLocationAccess = false;
break;
case Windows.Devices.Geolocation.GeolocationAccessStatus.Unspecified:
MessageBox.Show("Failed to access Windows 10 location API", "Error");
UwpDesktop.hasLocationAccess = false;
break;
}
}
However I get the following error when I run my app if the location permission is not enabled for it:
System.Exception: 'Element not found. (Exception from HRESULT: 0x80070490)'
The cause of this error as far as I can tell is that the RequestAccessAsync function needs to be run in the main UWP UI thread. The reason it only happens when the location permission is not enabled is because Windows tries to launch a UWP dialog requesting that the user grant location access, but fails to do so in a Desktop Bridge app.
I'm aware of two solutions to this problem. One would be to launch the Location section of the Settings app and show a messagebox to users asking them to grant location access there, which could work but I would really prefer to use the official API. The other option is to create a new UWP code project and write this code there, and then run it from the WPF app.
Microsoft has some documentation that is supposed to explain how to do the second option, but their examples are complicated and I don't know how to apply them to what I'm trying to do. I don't want to create a XAML UI or a background service, all I need is a way to safely call RequestAccessAsync and return a value based on the outcome. I'm wondering if I really need to create a UWP project to make this behave the way I want, or what the simplest way would be to go about it.
I’m trying to log some stuff to ETW on my UWP application deployed to RPI2 (Windows IOT v.10.0.15063.0). On device portal I can see new logs but message is empty (payload gives me: “stringmessage:,”)
var _loggingChannel = new LoggingChannel("HA4IoT", null, new Guid("4bd2826e-54a1-4ba9-bf63-92b73ea1ac4a"));
_loggingChannel.LogMessage("Test", LoggingLevel.Information);
I’m trying to use LogEvent instead but any string field behaves like that - values logged are empty and saved CSV also have no data about logged stuff.
Sorry you hit this - there's a known regression in the ETW parsing logic in the Creator's Update for Device Portal that we're working to fix. Right now we don't have a workaround except to write a WPR profile and collect an ETL, and use the ETL to collect your logs.
You can track our fix here: https://wpdev.uservoice.com/forums/110705-universal-windows-platform/suggestions/18591439-loggingchannel-not-showing-string-message-content
I'll update it when the code is fixed in an Insiders flight, and then once we know if the fix can be backported.
Update: This is fixed in the Fall Creators Update, and has been in flights for a couple months. Expect to see it in the next update of Windows across platforms.
On my Raspberry Pi2 it works. I copied your code and executed it.
My Windows IoT Core 10 version is: 10.0.14393.67
The result looks like this:
I set the target version of the IoT background application to the following:
The CSV export also looks fine on my machine:
Timestamp,Provider,ID
04/27/2017-21:23:36.8150656,HA4IoT,0,Keyword:1,Level:4,ProviderName:HA4IoT,StringMessage:Test,TaskName:LogMsgInformation,WebbCompletePayload:stringmessage:test,
Best regards,
Christian
I try to solve problem with the Windows Phone Launcher.
I have application and I would like to call another application using the uri and pass it some data. And I would like to know if the second application started. If the application was not started I would like to do some fallback.
Example:
bool result = await Windows.System.Launcher.LaunchUriAsync(new Uri("secondApp://data/123", UriKind.RelativeOrAbsolute));
if (!result)
{
// Opps. The second application is not installed.
ShowToast("Oops. The applications is not installed.");
UseInternalTinyFunctionalityInstead();
}
But the result is always true. Even though the second application is not installed. And additionally the windows message box is displayed "Search for app in the Store? You need to install an app for this task. Would you like to search for one in the Store? yes, no".
Is it possible to check if the second application was started/ is installed?
Is it possible NOT to display this dialog?
Thank you.
Myth Rush
I am using compact framework 3.5 to build a windows mobile application.I need to restart the application after saving the application settings. I tried the below one,from How do I restart my C# WinForm Application?
string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
Process.Start(path, "");
I am not getting any error,but my application is not restarting.I am checking in my simulator.Do restart working in mobile simulator.
Need solution to solve this problem.
Thanks
Try using this code to access the path:
string path;
path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
But to restart the application you can use RunAppAtTime method:
var time = DateTime.Now.AddSeconds(3); // immediate restart
Notify.RunAppAtTime(thisName, time); // restart the app
Note that although the time is set to 3 seconds from now it will restart immediately. To have a real delay the time difference must be higher than 10 seconds.
More on that here: https://stackoverflow.com/a/6133136/3330348
An .net application can not restart itself. As it is running on Mobile only one instance is ensured by the framework, if you had targetted Windows CE, you would be able to run multiple instances.
So, RunAppAtTime is a good solution to let the app be started by the Mobile scheduler after the app itself has terminated using Application.Exit().
Another option would be a second application that is started at Application.Exit(), watches the process list to see when main applicaton is terminated (or use GetProcessExitCode), and then starts a new instance of main application. This techique is used for updaters etc.
I am developing an WP8 app that uses a webbrowser control that shows statefull server content. On WP8 you can switch between apps manually. E.g. if you want to copy&paste some information from one app into a browser input field. If you switch that way, the current app instance stays alive. That means the web session and the current page of the browser control will stay available.
Now I want another app to send some data directly into the app with the browser control - without restarting it...
From what I know, there are three ways to handle inter app communication:
register a file type that will open the app by launching that file from local storage
register an app protocol and use Launcher.LaunchUriAsync() to submit parameters in a query string
use a shared storage file
Detailed information can be found here.
I think the last approach is not usefull, because after you have started the second app, there is now way to activate the calling app or is there any usefull way to reactivate the webbrowser app?
I tried the second approach, but I am running in an issue, because it starts a new instance by design. That means InitializePhoneApplication is called. There is the entry point for the custom UriMapper that reads the incoming parameters. So the old app instance is killed and all session data, cookies and input fields are gone. With WP webbrowser control you are not able to store the cookie and page state, so a fast app resume is not possible also.
private void InitializePhoneApplication()
{
if (this.phoneApplicationInitialized)
{
return;
}
RootFrame = new TransitionFrame();
RootFrame.Navigated += this.CompleteInitializePhoneApplication;
RootFrame.UriMapper = new AssociationUriMapper();
//...
this.phoneApplicationInitialized = true;
}
Is there any other way or a possibility to use the shown approaches to send data between apps without restarting them using LanchUri()?
That means, to send some data back to a running instance without reinitializing the whole app, so that the page state and session state are still available on the target app.
Best regards
Holger
FastAppResume is the solution. I haven't used it and thought it also reinitiates the app. But it doesnt. This example shows how to reuse the existing instance.
Regards
Holger