I'm using a Modal Loader in a WPF Application to indicates to the user some background processing.
All works fine with keyboard and mouse, but when it runs in a Windows tablet the application freezes executing this procedure:
public void Complete(bool focusOnWhoCall = true)
{
try
{
Dispatcher.InvokeShutdown();
}
catch { }
}
Running with the remote debugger, when froze, I pause the running. The visual studio execution pointer is on InvokeShutdown. Then I continue and it executes... It keeps freezed... I pause again and it stopped in the same point.
I uploaded this video on youtube to show the problem: https://youtu.be/IryEJ-YF168
I start using the mouse. All fine. When I use the touch at the first time its freezes... I don't know what to do anymore...
I make a project sample, every can download here: https://onedrive.live.com/redir?resid=F4B7C28FAD05ECCD!3743&authkey=!AHs6dcCjRGJmB4c&ithint=file%2czip
Thank's in advance!
Related
Looking for some feature that can make my app start up even fast, I found the prelaunch feature in the Microsoft documentation that would help open the app faster. But even if I register the app to enable prelaunch, the OnLaunched event keeps getting false in e.PrelaunchActivated.
(I only could test this feature using the VS option 'Debug UWP Prelaunch' in debug mode).
Do I need a Microsoft certificate to use it?
How long does the OS take to understand that my app is eligible to prelaunch?
Does this influence the fact that I'm getting false at the event?
I made a test and the prelaunch works correctly. I'll post my code here and explain how the prelaunch works. Hope it will help you solve your question.
Here is the sample code that I used:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
bool canEnablePrelaunch = Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch");
// ********
// some other code here
// *********
//check if it is prelaunched
if (e.PrelaunchActivated == false)
{
// On Windows 10 version 1607 or later, this code signals that this app wants to participate in prelaunch
if (canEnablePrelaunch)
{
TryEnablePrelaunch();
}
// ******
// normal code
// ******
}
else
{
//prelaunched
// do some logic that don't require UI thread.
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), "PreLaunched");
}
// Ensure the current window is active
Window.Current.Activate();
}
}
As you could see, I add an else sentence to do the work when the app is prelaunched.
When testing via the Debug Universal Windows App Prelaunch mode in Visual Studio, the whole process should be like:
Choose the Debug Universal Windows App Prelaunch mode, then the app will be prelaunched.
The OnLaunched event will be fired and you will go into the else sentence because it is prelaunched.
You could do your work in the OnLaunched event for prelaunched
Then the app will go to suspend status.
Now, the user launches the app from Start Menu.
The OnLaunched event will be fired again and this time it will show e.PrelaunchActivated == false because it is launched by the user, it is not prelaunched. I suspect this is the behavior that you are getting.
So this is the whole process about how the prelaunch works. This is also mentioned here: App launch.
In my case, Windows does not use Prelaunch when app is deployed by Visual Studio, but after installing it from the Store it works as expected. User must run an app at least one time and next time you will see it in the Task Manager. Will it work or not, depends on the amount of available memory, but I found it working even on a device with 4Gb of RAM.
Minimized Hololens application stops recognize air-taps.
It happens when you've let the app go idle for a while and then try to restart your session.
the gaze will turn into a doughnut but it won't do anything when you air tap.
void OnApplicationPause(bool paused)
{
if (!paused)
{
GestureListener.Instance.OnDisable();
GestureListener.Instance.OnEnable();
}
}
I do this each time I invoke app but it doesn't help.
I have a IOS app which show product details and for the AR section it opens another unity app.What I want to do is Quit the Unity app and go back to same page in the main app.I have used the following code.
public void BackHome()
{
Application.Quit();
}
The problem with this code is it quits like termination not smooth closing of app.Also it goes directly to the Home screen not to the app (that is main app page from where the Unity App opened up).What I want to do is open Unity app from the main app and after that while hitting a back button would like to close the unity app and return to the main app.
In player setting in Unity I have given Behaviour in BackGround - Exit.
Before Application.Quit, try open main app by URLSCHEME: Application.OpenURL("XXXXXX").
I'm playing with Microsoft's UWP AppServiceBridgeSample (here).
It is working well, but I would like to get rid of the console window of the BackgroundProcess application. The reason for this is that my BackgroundProcess starts another Win32 desktop application and works only as a mediator, so I don't want to disturb users with a console window. (Yes, it can be minimized, but I would rather not show it at all).
I have tried to hide it using the API mentioned here, but with no luck, the console window is still visible. Neither did switching the project's output type from Console Application to Windows Application.work.
Another thing I have tried was to create other BackgroundProcess project as a Windows application. It runs fine until I call AppServiceConnection.OpenAsync(), which causes the BackgroundProcess application to exitstrong text, thus the connection to UWA is not available.
static async void ThreadProc()
{
try
{
AppServiceConnection connection = new AppServiceConnection();
connection.AppServiceName = "CommunicationService";
connection.PackageFamilyName = Windows.ApplicationModel.Package.Current.Id.FamilyName;
connection.RequestReceived += Connection_RequestReceived;
AppServiceConnectionStatus status = await connection.OpenAsync();
//status check etc. ...
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
It seems that opening the AppService connection is only possible from a console app.
So here are my two questions:
Is it, by any chance, even possible to hide the background process' console window?
Can I use the background process as a Windows application, without AppServiceConnection failing during OpenAsync calls?
Re 1: Go into the project settings and change the output type from Console to Windows app. Also make sure the Main() function doesn't exit until you are done with the background process. Here is a better sample that shows this with a Windows Application:
https://stefanwick.com/2017/05/26/uwp-calling-office-interop-apis/
Re 2: AppServiceConnection works the same way from a windowed application as well. Make sure you add the right reference to the Windows.winmd to be able to build. If you have trouble with that, please post a specific question with details of the problem you are seeing
When the BackgroundAudioTask for my app is cancelled by other app on Windows Phone 8.1 which also uses BackgroundAudioTask, when I go back into my app, it will no longer play audio in the background. It will play fine when the app is running but if it is suspended - the background audio also stops.
The steps to reproduce this issue are:
I launch the Windows Phone 8.1 app which has a BackgroundAudioTask & everything works fine. I that start another app, for example the Music player, that uses a BackgroundAudioTask it will cancel the BackgroundAudioTask of my app.
When I launch my app for the second time, I want to re-register my BackgroundAudioTask so that it will behave as it did originally.
In Package.appxmanifest I have the following:
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="WindowsPhoneBackgroundAudioTask.BackgroundAudioTask">
<BackgroundTasks>
<Task Type="audio" />
</BackgroundTasks>
</Extension>
</Extensions>
When I first run the application the Run method will be called and I add a Deferral to the task to make sure it is kept alive even when I close my application:
public void Run(IBackgroundTaskInstance taskInstance)
{
setupDeferral = taskInstance.GetDeferral();
}
When I start the music player from another application my BackgroundAudioTask Cancelled event is called (If I don't do setupDeferral.Complete() here my application will crash):
private void Task_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
setupDeferral.Complete();
}
When I open my app how do I recreate my BackgroundAudioTask? The problem is the Run method is never called again so I can't setup the Deferral again. Music will now play fine in the app, but as soon as I navigate away from the app the music will stop.
I tried manually re-registering the task in App.xaml.cs in the App_Resuming event with this code:
var taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = "BackgroundAudioTask";
taskBuilder.TaskEntryPoint = typeof(WindowsPhoneBackgroundAudioTask.BackgroundAudioTask).FullName;
BackgroundTaskRegistration task = taskBuilder.Register();
The above code will throw and InvalidArgumentException because it does not have a Trigger setup. I don't want it to have a trigger. I just want to start the background task immediately.
Is there a way to manually instruct the OS to run the background audio again or a way to handle cancelled background audio better?
I know this is really old - but maybe someone will come across it. You actually don't need to register the task at all.
In the case of background audio, all you need to do is call
BackgroundMediaPlayer.Current
And it will fire up the task, and then your code will get the deferral.
I too had this same issue. The Background Audio Task wasn't starting playback once it was cancelled - either due to 5 minutes of inactivity, or due to another app. I was referring the sample code given by Microsoft here.
After hours of searching on the internet, I didn't find a solution. Then, digging in my code further, I found out that when the task is cancelled, the BackgroundMediaPlayer.Current.CurrentState becomes MediaPlayerState.Closed.
Hence, in order to restart the task/background audio playback, just set a source to the BackgroundMediaPlayer.Current again. In the sample code, this media player object is referenced using a variable named mediaPlayer inside the PlaylistManager project component.
Although the sample has a piece of code to restart playback once the task is cancelled, it does not work.