Alarm code raises invalidoperation exception in Background task - scheduled-tasks

In my windows phone 8 app, I am using a ScheduledTaskAgent to do some code on schedule basis.
During the task code, I am running an alarm at start immediately. I am using below code to do Alarm
Alarm alarm = new Alarm("Test Alarm");
alarm.Content = "My Test alarm";
alarm.BeginTime = DateTime.Now.AddSeconds(2);
alarm.ExpirationTime = alarm.BeginTime.AddSeconds(5);
alarm.RecurrenceType = RecurrenceInterval.None;
alarm.Sound = new Uri("/Assets/Beep.wav", UriKind.RelativeOrAbsolute);
// Add the reminder to the ScheduledActionService
ScheduledActionService.Add(alarm);
At scheduledactionservice add place, i am getting below exception:
System.InvalidOperationException: BNS Error: The API can only be called from foreground app.
Any help?

You can't add a scheduled task from a background agent, only from the app itself. You need to schedule the alarm from your UI code.

Related

isolate can't show local notifications and flutterisolate does not persiste after app killed

Ok. so i've written an isolate to show notifications more than once every 15 minutes.
If i use FlutterIsolate the isolate does not continue to persist after the app is killed.
If i use the method: Isolate, i get the following error message on showing a flutter_local_notification:
error: native function 'Window_sendPlatformMessage' (4 arguments) cannot be found
I've tried using sendport and receive port to keep the notifications running from within the ui thread. The code i've tried is below. I'm using the latest flutter_local_notificaion paackage and have tried flutter-dev.
Isolate isolate = await Isolate.spawn(isolated, 'args' );
produces the afformentioned error.
FlutterIsolate isolate = await FlutterIsolate.spawn(isolated, 'args' );
does not persist.
I would like to show local notifications as part of an isolate. Any way out of this predicament?

Error getting main window kAXErrorServerNotFound - Cannot Find the Target Application

My XCUITest will fail on one screen because of cannot Find the Target Application:
Could anyone please give some suggestion here? I don't understand how comes when first land on this screen the script can still locate the Application, but a few seconds later, it could not? thanks a lot!
------------ Here's the log -----------
t = 22.83s Tap Target Application 'com.ss.bbapp'
t = 22.83s Wait for com.ss.bbapp to idle
t = 22.89s Find the Target Application 'com.ss.bbapp'
t = 23.98s Find the Target Application 'com.ss.bbapp' (retry 1)
t = 25.04s Find the Target Application 'com.ss.bbapp' (retry 2)
t = 25.21s Assertion Failure: SearchScreen.swift:219: Error getting main window kAXErrorServerNotFound
t = 25.25s Tear Down

PowerBuilder restart function

We are using Restart function in an application to close the application and re-open the same when the application is left idle for the specified period of time.
The fucntion works fine when we call the function from SDI application but when we call the function from MDI, the application closes off after couple of restarts.
In MDI frame, when the function is trigger is first time, the application restart works fine. When we leave the application for another idle time and the restart function is triggered again, the applicaiton just closes off. It does not crash or anything but just closes. Any idea on how to troubleshoot and solve the issue. Thanks.
One approach is after the idle event triggers, open a new instance of the application then close self.
This simple example is not designed to function in the IDE.
[PB external function declaration]
FUNCTION int GetModuleFileNameA(&
ulong hinstModule, &
REF string lpszPath, &
ulong cchPath) LIBRARY "kernel32" alias for "GetModuleFileNameA;ansi"
[in the application open event]
if commandline = "RESTARTED" then
messagebox( "Welcome Back!", "Click to Continue" )
end if
idle(300) // Restart the application if there is no activity for 5 minutes
Open ( w_main )
[in application IDLE event]
string ls_ExePathFileName
unsignedlong lul_handle
ls_ExePathFileName = space(1024)
lul_handle = Handle(GetApplication())
GetModuleFilenameA(lul_handle, ls_ExePathFileName, 1024)
run( ls_ExePathFileName + " RESTARTED" )
HALT CLOSE

Stop httputils service in basic4android

I am using basic4android and I made an application that uses httputils services. Sometimes a remote error occurs (possible server overload or limited internet connection) and the application exits with the error message box. The activity closes but httputils service is still running. While I reopen the activity new error occurs, because of the unfinished job of httputils. Everything is OK only if I choose to stop the activity in the second error.
Is there any way to determine if the httputils service is running by a previous instance of my app? Or better, a way to try to stop this service either its running or not.
HttpUtils errors should not cause your program to exit. You should check IsSuccess to make sure that the call succeeded or not.
You can stop the service from running by calling StopService(HttpUtilsService).
Public Sub StationTransfer_Click
Dim job As HttpJob
job.Initialize("MyJob", Me)
Dim URL As String="https://www.yourserver.com/myjob.asmx/GetData?parameter1=abc"
job.Download(URL)
ProgressDialogShow2("Getting data From Server...", True)
End Sub
Sub JobDone(Job As HttpJob)
Select Job.JobName
Case "MyJob"
HandleMyJob(Job)
End Select
Job.Release
End Sub
Sub HandleMyJob(Job As HttpJob)
If Job.Success = False Then
ToastMessageShow("Error downloading Data", True)
ProgressDialogHide
Return
End If
....
end Sub
if there is an httpjob error you catch it in the handler function by looking at the status. if the status is not success than you catch it and display a message.

Display progress when running long operation?

in my ASP.NET MVC3 Project, I've got an action which runs a certain amount of time.
It would be nice, if it could send partial responses back to the view.
The goal would be to show the user some progress-information.
Has anybody a clue how to make that work?
I did a try with some direct output to the response, but it's not being sent to the client in parts but all on one block:
[HttpPost]
public string DoTimeConsumingThings(int someId)
{
for (int i = 0; i < 10; i++)
{
this.Response.Write(i.ToString());
this.Response.Flush();
Thread.Sleep(500); // Simulate time-consuming action
}
return "Done";
}
In the view:
#Ajax.ActionLink("TestLink", "Create", new AjaxOptions()
{ HttpMethod = "POST", UpdateTargetId="ProgressTarget" })<br />
<div id="ProgressTarget"></div>
Can anybody help me making progressive action-results?
Thanks!!
Here's how you could implement this: start by defining some class which will hold the state of the long running operation -> you will need properties such as the id, progress, result, ... Then you will need two controller actions: one which will start the task and another one which will return the progress. The Start action will spawn a new thread to execute the long running operation and return immediately. Once a task is started you could store the state of this operation into some common storage such as the Application given the task id.
The second controller action would be passed the task id and it will query the Application to fetch the progress of the given task. During that time the background thread will execute and every time it progresses it will update the progress of the task in the Application.
The last part is the client: you could poll the progress controller action at regular intervals using AJAX and update the progress.