BlackBerry - Uncaught exception: Application is not responding; process terminated - blackberry

I'm developing an application using the Blackberry plugin for eclipse and I am getting the following error when making a call to a web service when I have deployed my application to a production server and handset... it works in my local simulator and development environment. (I can't hook my simulator directly to my production environment)
Uncaught exception: Application
app(150) is not responding; process
terminated
The call is being made from another thread.
The thread is passed to my CustomThreadManager to run
ClientChangeThread thread = new ClientChangeThread();
CustomThreadManager.Start(thread, true);
CustomThreadManager
ProgressPopup _progress = null;
if(showProgress){
_progress = new ProgressPopup("Loading...");
_progress.Open();
}
thread.start();
while (thread.isRunning())
{
try
{
CustomThread.sleep(300);
if(showProgress){
_progress.doPaint();
}
}
catch (InterruptedException e)
{
Dialog.alert("Error contacting webservice\n" + e.getMessage());
Functions.moveBack();
}
}
if(showProgress)
_progress.Close();
Some calls work while others dont.
The web service returns results fairly quickly so Im not sure if its the web service is too slow or problems with the threading.
Any help appreciated.

Thread.sleep() does not release any locks. This means your code to update the progress bar in the while-loop is holding the UI event lock, and prevents other UI updates from happening until the while loop terminates -- in this case when thread.isRunning() returns false.
You can use UiApplication.invokeLater(Runnable, long, boolean) to schedule a repeating UI update that will only hold the event lock while the Runnable is executing.

Related

How to keep .NET Core console app alive in Docker container

I am testing a .NET Core 2.0 app which uses the Service Bus SDK to retrieve messages from an Event Hub. I setup a console app to do that, and intend to run the app as a Docker container.
This method creates the Event Host Processor which will read the messages:
private static async Task MainAsync(string[] args)
{
Console.WriteLine("Registering EventProcessor...");
var eventProcessorHost = new EventProcessorHost(
EhEntityPath,
PartitionReceiver.DefaultConsumerGroupName,
EhConnectionString,
StorageConnectionString,
StorageContainerName);
// Registers the Event Processor Host and starts receiving messages
Console.WriteLine("Retrieving messages");
await eventProcessorHost.RegisterEventProcessorAsync<EventProcessor>();
Console.WriteLine("Sleeping");
Thread.Sleep(Timeout.Infinite);
}
As the event processor implemented in class EventProcessor will be the one handling the events, I am trying to prevent the console app to exit when the registration of the Processor is finished.
However, I can't find a reliable way to keep the app alive. If I run this container as-is, all I see in the output window is:
Registering EventProcessor...
Retrieving messages
Sleeping
and no messages are ever received.
Thanks all for the suggestions.
I followed those articles but eventually ended up with this, which applies specifically to .NET Core apps:
https://github.com/aspnet/Hosting/issues/870
I've tested it and the app can shutdown gracefully when it receives a termination signal from the Docker runtime.
UPDATE: this is the relevant sample from the GH issue link above:
public class Program
{
public static void Main(string[] args)
{
var ended = new ManualResetEventSlim();
var starting = new ManualResetEventSlim();
AssemblyLoadContext.Default.Unloading += ctx =>
{
System.Console.WriteLine("Unloding fired");
starting.Set();
System.Console.WriteLine("Waiting for completion");
ended.Wait();
};
System.Console.WriteLine("Waiting for signals");
starting.Wait();
System.Console.WriteLine("Received signal gracefully shutting down");
Thread.Sleep(5000);
ended.Set();
}
}

Dart Web Server: prevent crash

Id'like to develop a web services + web sockets server using dart but the problem is I can't ensure the server's high availability because of uncatched exceptions in isolates.
Of course, I have try-catched my main function, but this is not enough.
If an exception occurs in the then() part of a future, the server will crash.
Which means that ONE flawd request can put the server down.
I realize that this is an open issue but is there any way to acknoledge any crash WITHOUT crashing the VM so that the server can continue serving other requests ?
Thank you.
What I've done in the past is use the main isolate to launch a child isolate which hosts the actual web server. When you launch an isolate, you can pass in an "uncaught exception" handler to the child isolate (I also think you should be able to register one at the top-level as well, to prevent this particular issue, as referenced by the issue in the original question).
Example:
import 'dart:isolate';
void main() {
// Spawn a child isolate
spawnFunction(isolateMain, uncaughtExceptionHandler);
}
void isolateMain() {
// this is the "real" entry point of your app
// setup http servers and listen etc...
}
bool uncaughtExceptionHandler(ex) {
// TODO: add logging!
// respawn a new child isolate.
spawnFunction(isolateMain, uncaughtException);
return true; // we've handled the uncaught exception
}
Chris Buckett gave you a good way to restart your server when it fails. However, you still don't want your server to go down.
The try-catch only works for synchronous code.
doSomething() {
try {
someSynchronousFunc();
someAsyncFunc().then(() => print('foo'));
} catch (e) {
// ...
}
}
When your async method completes or fails, it happens "long" after the program is done with the doSomething method.
When you write asynchronous code, it's generally a good idea to start a method by returning a future:
Future doSomething() {
return new Future(() {
// your code here.
var a = b + 5; // throws and is caught.
return someAsyncCall(); // Errors are forwarded if you return the Future directly.
});
}
This ensures that if you have code that throws, it catches them and the caller can then catchError() them.
If you write this way, you have much less crashes, assuming that you have some error handling at the top level at least.
Whenever you are calling a method that returns a Future, either return it directly (like shown above) or catchError() for it so that you are handling the possible errors locally.
There's a great lengthy article on the homepage that you should read.

MAF: Add-in crashes host even when run in seperate process

I am using MAF for my Addin development. All seems to be working fine, but one issue needs be sorted...
I activate the plugin in their own process, i,e, using
var process = new AddInProcess();
myAddinToken.Activate(process,AddInSecurityLevel.FullTrust);
When an unhandled exception occurs in the add-in, my host crashes!
Since i am running the addin in a seperate process, why i am i still seeing my host app crash because of an unhandled exception in the ad-in?
Is it not supposed to simply crash the add-in specific dedicated process, and leave the host process as-is live?
Any ideas how to fix this?
What is the exception that crashes your app?
Do you have an UI element coming from your AddIn?
With the UI I had to close / dispose the UI elements on the host side properly and also catch RemotingException
Maybe this helps you a bit:
AddInToken grailAddInToken = addInTokens[0];
AddInProcess addInProcess = new AddInProcess();
addInProcess.Start();
Process process = Process.GetProcessById(addInProcess.ProcessId);
process.EnableRaisingEvents = true;
process.Exited += (s, e) => synchronizationService.Invoke(() =>
{
window.Close();
});

C builder RAD 2010 RTL/VCL Application->Terminate() Function NOT TERMINATING THE APPLICATION

I have a problem also described here: http://www.delphigroups.info/3/9/106748.html
I have tried almost all forms of placing Application->Terminate() func everywhere in the code, following and not 'return 0', 'ExitProcess(0)', 'ExitThread(0)', exit(0). No working variant closes the app. Instead the code after Application->Terminate() statement is running.
I have two or more threads in the app. I tried calling terminate func in created after execution threads and in main thread.
Also this is not related (as far as I can imagine) with CodeGuard / madExcept (I have turned it off and on, no effect). CodeGuard turning also did not do success.
The only working code variant is to place Application->Terminate() call to any of any form button's OnClick handler. But this does not fit in my needs. I need to terminate in any place.
What I should do to terminate all the threads in C++ Builder 2010 application and then terminate the process?
Application->Terminate() does not close application immediately, it only signals you want to close the application.
Terminate calls the Windows API
PostQuitMessage function to perform an
orderly shutdown of the application.
Terminate is not immediate.
In your functions call Application->ProcessMessages() then check if the Application->Terminated property is true.
For applications using
calculation-intensive loops, call
ProcessMessages periodically, and
also check Terminated to determine
whether to abort the calculation and
allow the application to terminate
For example:
void Calc()
{
for (int x = 0; x < 1000000; ++x)
{
// perform complex calculation
// check if need to exit
Application->ProcessMessages();
if (Application->Terminated)
{
break;
} // end if
} // end for
// clean up
}

Application crashes with Exception when using javax.microedition.media.Player

I have an application that processes data from bluetooth and send it to the web service. Recently there was a request to add sounds to the application. Now when the application processes batches of data and the player is playing constantly after a few secs I get "Application is not responding" exception. And then the process is terminated. In the logs I can see lots of ForcedStackTrace exception logged after this exception.
The sounds are played in the separate thread. If app doesn't play sounds or plays short sounds - everything works fine. Is there any way to avoid this exception happening? Why is it happening?
InputStream mediaStream = null;
try {
mediaStream = getClass().getResourceAsStream(relativePath);
getLogger().log("setting player _ " + _audioType);
setPlayer(Manager.createPlayer(mediaStream, _audioType));
_currentPlayer.addPlayerListener(this);
_currentPlayer.setLoopCount(1);
_currentPlayer.realize();
VolumeControl vc = (VolumeControl) _currentPlayer
.getControl("VolumeControl");
if (vc != null) {
vc.setLevel(_voumeLevel);
}
_currentPlayer.prefetch();
_currentPlayer.start();
} catch (Exception e) {
}
(crossposted from BB forums)
Resolved by implementing my own PlayerManager, which, running in a separate thread would play the item in the queue manner rather then having many threads using the inner Player implementation.

Resources