BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 09-17-2007, 07:36 AM   #1 (permalink)
Thumbs Must Hurt
Join Date: May 2007
Location: Bulgaria
Model: none
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default SocketConnection as a Thread - Stopping it?

Please Login to Remove!

I hava a class (Sync) that extends Thread. I have opened a SocketConnection, connect to a server, make some data synchronization. During the sync process I would like to stop the synchronization (close the connection) from the main thread. I tried diferent ways to solve the problem:

1) I tried with Dialog.ask(....)...but it is modal and the process of synchronization is stopped while the system is waiting for my answer.
2) I made my own "Cancel" button to stop the sync process, but it looks like the main thread is sleeping or something like that (i could not move the focus to that button)
3) I use the back key, but it works after the sync process.
Here is a part of my code:
private void sync() {
    Sync sync = null;
    prog = new ProgressStatus();
    synchronized (prog) {
      if (!isRunning) {
        isRunning = true;
        isCancelled = false;
        sync = new Sync(prog, dataBase, isCancelled, dataLimit, isRunning);
        isRunning = sync.getIsRunning();
    while (isRunning) {
      Backlight.enable(true, 200);"synchronizing...");
      try {
      } catch (InterruptedException exception) {
        Dialog.alert("Exception: " + exception);
      synchronized (prog) {
        isRunning = sync.getIsRunning();

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.