I'm trying to restart the application, but I get NotInForeground error every time.
I tried to close every other application and loop the restart attempt to make sure it is in foreground like this
var loopRestart = true;
while (loopRestart)
{
var failureReason = await CoreApplication.RequestRestartAsync("-fastInit -level 1");
loopRestart = failureReason == AppRestartFailureReason.NotInForeground;
}
With or without parameters (from one of the examples found on the internet) it just won't let me do it. When I do CoreApplication.GetCurrentView() is says that the window is ActivatedInForeground quickwatch. At this point I'm lost. Version is 2004
Related
Launching of the desktop application was working fine when I automated using winAppDriver.
Of late I observed these tests are failing.
Its failing at this line,
notepadsession = new WindowsDriver(new Uri("http://127.0.0.1:4723"), desiredcapabilities);
I tried both the codes, but still failing:
var currentWindowHandle = notepadsession.CurrentWindowHandle;
Thread.Sleep(TimeSpan.FromSeconds(5));
var allWindowHandles = notepadsession.WindowHandles;
notepadsession.SwitchTo().Window(allWindowHandles[0]);
if (notepadsession.CurrentWindowHandle != notepadsession.WindowHandles.Last())
{
notepadsession.SwitchTo().Window(notepadsession.WindowHandles.Last());
}
NOTE: It takes around 40-50 seconds to load the Desktop application.
Any help in this regard is highly appreciated.
Thanks
Below code solved the problem
notepadsession = new WindowsDriver(new Uri("http://127.0.0.1:4723"), desiredcapabilities);
Thread.Sleep(5000);
notepadsession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
The ms:waitForAppLaunch capability enables WinAppDriver to wait for a defined amount of time after an app launch is initiated prior to attaching to the application session. The limit for this is 50 seconds.
C#: appCapabilities.SetCapability("ms:waitForAppLaunch", "25"); to add app delay of 25 seconds.
For more information check out the release notes.
I am trying to close the most recent window/tab of IE but when I call the Kill method the window relaunches without the content of the page.
This is the code that I use to get the most recent IE process:
var a = System.Diagnostics.Process.GetProcessesByName("iexplore");
DateTime earliestStart = DateTime.Today.Subtract(new TimeSpan(1,0,0,0));
System.Diagnostics.Process youngestProccess = a.FirstOrDefault();
foreach(var b in a){
if (b.StartTime > earliestStart)
{
earliestStart = b.StartTime;
youngestProccess = b;
}
}
youngestProccess.Kill();
The code is working in the way that the most recent window "stop" working but the window is not beeing closed
Any idea?
Hi I just discover how to solve the problem.
The message is being thrown because my IE has the option "Enable automatic crash recovery" checked in the Internet Options Advanced tab.
So if you face this you have 2 options: un-check that option forever (which might work for your case) or like in my case you can change the selection via registry keys and when you finish your testing return the value to be on.
So to do this you need to add this to your code before opening IE.
Registry.SetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Recovery", "AutoRecover", 2);
To turn back on the option you must do the same but with a 0
Registry.SetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Recovery", "AutoRecover", 0);
I've been banging my head against the monitor for the last few days. I'm developing an UWP app for the Windows Store (targeting 14393) and I'm using Prism/Unity frameworks for MVVM / IoC.
Since the data needed to update the Live Tile is stored in a class implementing the Repository pattern and everything is managed through Unity, I'm not creating a separate process for background execution, therefore even simplifying the whole BGTask registration process.
The actual BGTask registration code is as follows:
var servicingTaskAlreadyRegistered = false;
var tileUpdaterTaskAlreadyRegistered = false;
foreach (var t in BackgroundTaskRegistration.AllTasks)
{
if (t.Value.Name == Constants.BgTileUpdaterTaskName)
tileUpdaterTaskAlreadyRegistered = true;
else if (t.Value.Name.Equals(Constants.BgServicingTaskName))
servicingTaskAlreadyRegistered = true;
}
var reqAccess = await BackgroundExecutionManager.RequestAccessAsync();
if (reqAccess == BackgroundAccessStatus.Denied ||
reqAccess == BackgroundAccessStatus.DeniedBySystemPolicy ||
reqAccess == BackgroundAccessStatus.DeniedByUser ||
reqAccess == BackgroundAccessStatus.Unspecified)
return false;
if (!servicingTaskAlreadyRegistered)
{
var servicingTaskBuilder = new BackgroundTaskBuilder();
servicingTaskBuilder.Name = Constants.BgServicingTaskName;
servicingTaskBuilder.SetTrigger(new SystemTrigger(SystemTriggerType.ServicingComplete, false));
servicingTaskBuilder.Register();
}
if (tileUpdaterTaskAlreadyRegistered)
return true;
var builder = new BackgroundTaskBuilder();
builder.Name = Constants.BgTileUpdaterTaskName;
builder.SetTrigger(new TimeTrigger(TileUpdateFrequencyMinutes, false));
//builder.SetTrigger(new MaintenanceTrigger(TileUpdateFrequencyMinutes, false));
builder.IsNetworkRequested = true;
builder.Register();
The registration successfully completes. Executing Get-AppBackgroundTask in PowerShell shows both tasks, as it should be. However, the TimeTrigger never fires. Swapping TimeTrigger with the MaintenanceTrigger fixes the problem, although the smartphone needs to be plugged to the charger which is not an acceptable workaround.
Forcing the task to run via VisualStudio or PowerShell (Start-AppBackgroundTask -TaskID ) correctly executes and the tile gets updated.
Do you have any other useful tip to share?
Edit 12/01/2017
I've created a Repro containing a Visual Studio Solution with two projects:
Live Tile Test Simple: as simple as it gets to have a live tile updating every 15 minutes using UWP. Everything works as expected.
Live Tile Test Prism: again, a simple conversion of the above project using Prism and Unity. Doesn't work because when the OS tries to launch the app to update the tile the Unity container is null (doesn't get initialized).
This explains why I'm having the problem: Unity doesn't get initialized, I'm unable to retrieve data via repositories, the app crashes and GG.
Now I just need to understand why Unity isn't available in the OnBackgroundActivated method. Almost there guys!!
Repro: https://github.com/eraser85/LiveTileTestRepro
The code looks fine to me, the only things I'd try to change here are the use of the IsNetwokRequested property and the TimeTrigger frequency value, are you sure that constant/variable you're using is greater or equal to 15?
Here's a sample:
BackgroundTaskBuilder builder = new BackgroundTaskBuilder { Name = "YourBgTaskName" };
builder.SetTrigger(new TimeTrigger(15, false));
builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
builder.Register();
Ok so after some more tests I've finally come up with a solution.
As mentioned, the problem stemmed from Prism: basically, when launched by the OS and entering via OnBackgroundActivated() the IoC container wasn't getting initialized.
The solution, even if seems hack-ish, is actually perfectly viable and correct (IMHO!). In your OnBackgroundActivated() just initialize everything as if starting from scratch (have a look at Prism's Source for implementation details): in my specific case, I just called CreateAndConfigureContainer() and re-registered everything I've put in OnInitializeAsync() (eg. repos, services..).
I've opened an issue with the devs. Maybe a solution is already on the way, but in the mean time this should do.
I am making a launcher app in C# on windows. However the process isn't directly started by my C# application but it uses a url to start it e.g "steam://rungameid/xxxxxxx"
I need it to monitor a process by name (say XYZ.exe) in the following fashion:
Receive an event when XYZ.exe starts
Receive an event when XYZ.exe exits
I just want to minimise and restore the my C# application's form when the application is running and not running respectively
thanks
Make a timer (with your preferred timer method) and poll every 'n' milliseconds (find what's best for you... I'd say for minimizing/restoring from a game, 500 milliseconds could be a good start, but experiment), then you can use something like:
bool processRunning = false;
void timerTickMethod()
{
var procIsRunning = Process.GetProcessesByName("xyz.exe").Any();
if(procIsRunning && !processRunning)
ProcessIsStartedEvent(); // or directly minimize your app
else if(!procIsRuning && processRunning)
ProcessIsEndedEvent(); // or directly restore your app
processRunning = procIsRunning;
}
If you want to make sure it's your xyz.exe that is running, you can pass in the full path to GetProcessesByName (so that if there's other xyz.exe in your system, it won't confuse your app)
Update
I was writing from memory, so maybe GetProcessesByName only work for friendly names (with no exe, or path).
If that's the case (I haven't tried), and you need the full path you could do it like:
var procIsRunning = Process.GetProcesses().Any(x => x.MainModule.Filename == #"c:\your\full\path.exe");
I'm wondering how could I check if an app is running inside the BlueStacks Application which simulates Android apps.
In my code, I'm using this line below to start the app, but how can I check if its already running? Note: The check function must work even tho the app has not been initialized by the code-line below. Lets suppose I started manually the app on bluestacks and then I request the check function
System.Diagnostics.Process.Start("C:/Program Files (x86)/BlueStacks/HD-RunApp.exe", "-p com.supercell.clashofclans -a com.supercell.clashofclans.GameApp");
The application mentioned as an example: Clash of Clans
At task manager, the process HD-Frontend.exe is shown whether im using the app i started or not. Which means i cannot use the process name to check if its running because it wont work properly.
private bool appRunning()
{
var runningProcessByName = Process.GetProcessesByName("HD-Frontend");
if (runningProcessByName.Length == 0)
return true;
else
return false;
}