BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-17-2007, 07:36 AM   #1
pa4o85
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
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:
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);
        sync.start();
        isRunning = sync.getIsRunning();
      }
    }
    while (isRunning) {
      Backlight.enable(true, 200);
      Status.show("synchronizing...");
      try {
        Thread.sleep(100L);
      } catch (InterruptedException exception) {
        Dialog.alert("Exception: " + exception);
      }
      synchronized (prog) {
        isRunning = sync.getIsRunning();
      }
    }
  }
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Chroma 6312 DC Electronic Load Mainframe  picture

Chroma 6312 DC Electronic Load Mainframe

$239.96



Used National Instruments SCXI-1000 Mainframe 1200 1120 1160(2) 181445D-01 U2 picture

Used National Instruments SCXI-1000 Mainframe 1200 1120 1160(2) 181445D-01 U2

$299.95



Hp Agilent 70001A Mainframe 70420A Opt 201 Test Set  picture

Hp Agilent 70001A Mainframe 70420A Opt 201 Test Set

$350.00



Fluke Networks Versiv Modular Mainframe AS IS picture

Fluke Networks Versiv Modular Mainframe AS IS

$1100.00



Tektronix 7904 Oscilloscope Mainframe  w/ 2x 7A26 2x 7B92A Modules picture

Tektronix 7904 Oscilloscope Mainframe w/ 2x 7A26 2x 7B92A Modules

$399.97



Used Teseo Image Mainframe W/OVCM02B OALM02B Amplifier Research F3 picture

Used Teseo Image Mainframe W/OVCM02B OALM02B Amplifier Research F3

$999.95







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