Termination of the thread

HELLO developers,

ublic  class Timer extends Thread
{
    static boolean isMsgSentMode =true;
    static int timerCount;
    static int count=0;
    int i = 10;
    public void run(){
        try{
            while(isMsgSentMode){
                if(i==-1)
                {
                    //TODO
                    // Add the code here
                    // implement the operation needed when the counter reaches to 0

                        // sending the query status command only once

                        if(count==0)
                        {
                            BluetoothSerialPortScreen.queryStatusCmd();
                        }
                        safeSetLabelText(MsgCenter.SOS_MESSAGE_SEND);

                        isMsgSentMode=true;

                        // when count greater than 2 it will come out of the loop

                        if(count>2)
                        {
                            isMsgSentMode=false;
                        }
                        count ++;
                        //i=10;  // resetting it to -1
                    }

                    else
                    {
                        isMsgSentMode=false;
                    }
                }
                else
                {
                    // for testing purpose

                    if(!(QueryStatusEntity.getmCurrentModeOfOperation()==3))
                    {
                        System.out.println("Thread is working "+i);

                        safeSetLabelText("SOS Will be send in"+ " "+ i+" "+"seconds");
                        Thread.sleep(1000);
                    }
                    else
                    {
                        isMsgSentMode=false;
                    }
                    i--;
                }

            }
        }

        catch(Exception e){

            System.out.println("Exception has been occured "+e.getMessage());
        }
    }

    /**
     *   Used to Modify the sosmessagesendLabelField called from the Thread
     *
     * @param text
     * @return LabelField
     */

    public final void   safeSetLabelText( String text) {
        synchronized (UiApplication.getApplication().getEventLock()) {
            SosModeScreen._sosmessagesendLabelField.setText(text);

            // based on the text type the setpadding is being changed

            if(text.equalsIgnoreCase(MsgCenter.SOS_MESSAGE_SEND))
            {
                SosModeScreen._sosmessagesendLabelField.setPadding(20, 0, 0, SpotConstants.WIDTH_BY_FOUR);
            }
            else
            {
                SosModeScreen._sosmessagesendLabelField.setPadding(20, 0, 0, SpotConstants.WIDTH_BY_SIX );
            }

        }
    }

    /**
     *   For stoping  the thread programtically
     */

    public synchronized static void stop()
    {
        isMsgSentMode=false;
    }

    /**
     *   For starting the thread programtically
     */

    public synchronized static void starts()
    {
        isMsgSentMode=true;
    }

I've set up a thread. that works very well for me, but the problem is that I can't stop this inorder to stop the current thread form execeuting I created a

 public synchronized static void stop()
    {
        isMsgSentMode=false;
    }

Timer.stop using (), I call it but is still the thread is running in the background, need help for this

Thank you

sujithRavindran

There is no sure method to end a thread.

usually you put into a Boolean variable that you can change from the outside.

If (! stop)-> stop process set to true and the termination of the thread.

Tags: BlackBerry Developers

Similar Questions

  • If you ask the question and then choose a solution, the thread will be closed or still can you ask more details?

    If you ask the question and then choose a solution, the thread will be closed or still can you ask more details?
    (sometimes, someone answers my question, and I want to mark it as the solution and am not yet quite ready for the thread be closed...)

    If you still experience this issue, you can return to this thread.
    But, you must clear the flag solved .

  • I'm not able to get the email to sort properly... not on the threads.

    No matter what I do the emails do not sort by date received, without rhyme or reason troubled crazy!

    So are you sure that's not on the threads?
    Go to View-sort by and tell me what are the 3 elements have markers next to them.

  • Why my forums is no longer show them not to read items as read after viewing the thread?

    When I go to a forum thread to appear in bold if it is unread since my last visit. After viewing the thread and return to the list the item used to change the non-bold meaning there is none unread in the thread. Now, it remains "BOLD" unless I leave the forum and then come back.

    By using the previous button to return to the page previous risk of Firefox display the version previously cached this page without updating the status of visited link.

    You can try to open links in a new tab with a middle click and close the tab to go back.

  • How to manage the threads for TCP communication?

    Hello

    I have a project to control two separate applications (C++ and LabView) and two of them are implemented as server. Another client program (C++) is used to control applications. Communication between them are implemented using TCP socket. The client program sends the message to start or stop tasks on servers. The client program also sends time (HH) with the message start and end to determine when to start or stop.

    Application in C++ (server): Listening to the request for the connection and when gets one, it creates a thread of communication allowing to manage this and listen again to another connection. Communication wire crossing of handles and messages when it receives a start or a stop message, it creates a thread of timer with the received time to trigger a task at the time specified. And after that he expects the client message. So, here, when the thread (communication, timer) is necessary, it is created.

    In LabView (server): I tried to create the same as the C++ server. But, in manual of LabView and other discussions of the forum, I got that LabView is multithreaded and it can be done with the help of the loop independent. So, I had to create four loops in a diagram:

    1. wait the new connection

    2 manage the communication for the already received connection

    3. start the timer

    4 stop the timer

    and they are executed at the beginning of execution and communication between them are managed using local variables. But, 2, 3 and 4th loop can handle only one connection and it can handle another if the current is closed. The C++ application can handle multiple connections by creating the thread when it is necessary, but not at the beginning of the application.

    Is there a better way to implement this in LabView?

    Is it possible to manage multiple connections and create the diagram node/block (such as a wire) dynamically as C++?

    Thank you.

    There are several ways to do so in modern LabVIEW and you should probably seek the Finder example for TCP examples. The classic is to transfer the refnum of connecting the listening loop in a communications loop that adds to an array of login credentials and then constantly iterates through this array to make the communication. He works on LabVIEW 4.0 perfectly for me even for applications with basic HTTP communication protocol. But you must make sure that the communication for a connection is not delaying his work for reasons that would delay the handling of other connections too, because they are really of course worked on sequentially. If you encounter an error, the connection ID is closed and removed from the table.

    The other is that create you a VI that makes your entire communication and ends on an error or when the order quite. Make this reentrant VI and then launch it through VI server as the instance home, passing the refnum of newly received connection form the listening loop. Then use the method to Run let start and operate as an independent thread.

    For all these, you should be able to find an example in the example Finder when searching for TCP.

  • How to determine the Thread of execution for PostUIMessage,

    Greetings:

    I'm trying to develop an application TestStand with two Interfaces (in addition to the sequence editor) user, and I need to be able to view messages from interface user back and forth between two user interfaces.

    So far I managed to create a user interface, and I can post messages for the user interface of a TestStand sequence to my user interface. large.  I spent the reference Application Manager in the constructor of the UI object.

    Now, I want a button on my first UI to cause a user interface message to send to my second UI... The PostUIMessage options I have are Engine.PostUIMessage or Thread.PostUIMessage... in both cases that I need the thread, I don't think I have unless I pass it explicitly in the constructor.  Ideally, I would like to pass only a single object in the constructor (to keep things simple).

    I tried to create versions of my first UI that pass the engine reference, or reference to the SequenceContext, but I seem to be impossible to extract the info that I need these.  For example, the SeqContext, in theory I can get the engine and the Thread, but when I try to get the reference of the AppMgr of engine

    TsEngine = seqContext.Engine;
    AppMgr = TsEngine.GetInternalOption (InternalOptions.InternalOption_ApplicationManager) (ApplicationMgrClass);

    I get the following exception:

    The instance of the .NET class could not be found.

    Impossible to object cast COM type 'System.__ComObject' to the class type 'NationalInstruments.TestStand.Interop.UI.ApplicationMgrClass '. COM components that enter the CLR and do not support IProvideClassInfo or who have not any registered assembly are wound in the __ComObject type. Instances of this type cannot be cast to any other class; However they can be cast to interfaces as long as the underlying COM component supports calls QueryInterface for the IID of the interface.
    Source: SidecarLib to

    What I really need to move the app Manager frame of reference and sequence and the thread as separate arguments my constructor, or I missed something that causes the exception above?

    Thank you very much

    Tom MacLean

    It seems I've found the problem.

    The code sample that I created on my user interface is from the article "launch of a floating .NET form in TestStand.  In this example, the reference of the Application Manager is in a member of the class defined as:

    Class AppMgr ApplicationMgr;

    If you try to get the referral of Application of the motor as this handler:

    AppMgr = seqContext.Engine.GetInternalOption (InternalOptions.InternalOption_ApplicationManager) (ApplicationMgrClass);

    It is then the exception mentioned above is generated.   If, however, the reference to Application Manager is defined as:

    ApplicationMgr AppMgr.

    and it is extracted in the context of the sequence as follows:

    AppMgr = seqContext.Engine.GetInternalOption (InternalOptions.InternalOption_ApplicationManager) (ApplicationMgr);

    everything works as I had planned (without exception).

    I hope that it can save someone else some grief.

    See you soon,.

    Tom MacLean

  • bad terminator in the Basler A504k CIM series

    I'm talking about in series of LV to a Basler A504k via a NOR-1429th and, despite what says in the compatibility report and in this post, I perfectly managed, at least as long as I tried. A (still unpolished) example of my order that VI is attached (LV8.6.1), for the sake of anyone running in my same problems.

    However, there is one thing that bothers me about the string terminator defined in the file of the camera. The original definition is

    TermChars (\x06)

    This is not correct.  \x06 is the character of the acknowledgement of receipt sent by the camera to recognize the command sent by the host was correctly formed; the channels are normally end with ETX, i.e. \x03, while the camera can be answered by a single NAK, i.e. \x15, if the query string is incorrect. For this device, the command for a reading sequence is (when it is correct) STX-query - ETX-> ACK-STX-response-ETX, so if ACK is used as an indicator of end, the response to the reading of orders is always lost. At least, so much as "IMAQ Serial Read.vi" is used; given that the format of the camera control is strict, an alternative using 'IMAQ series Read Bytes.vi' and the exact number of characters to read would still be possible.

    It was simple to change the TermChars to (\x03) entry in the file of the camera and with whom my VI essentially works, while the replay would not be with the bad terminator.  The only whim so far I am aware, is that I seem to be able to set Timer1 and Timer2, settings that control the rate of time and part of the exhibition, but not to reread, contrary to what the manual says (the camera meets always 0).

    Any comments on that?

    Enrico

    Correction to what I wrote just above - fixed read a number of bytes is required anyway, because the answer may contain binary camera the \x03 or whether in the data field. It was actually the reason why I couldn't read some specific areas, such as versions of firmware or the timer data.

    A corrected version of my previous vi is attached. As for me, the problem is now resolved - this message in one concern for others in my situation.

  • SetCtrlVal used during the Thread function works causes memory leaks

    I am writing a program that works if... Or not work if... - see the next lines... :-)...

    The program includes a section, mostly GUI - and User Interaction.

    The other part is a DLL. In the DLL we readings on an external consultant controller RS232. Sometimes the controller card needs (called how much) time and this time must pass then the result can be read card controller... and so on...

    Blocking is not GUI-user-program for the expectation of the return value of the DLL functions (which need a few seconds to be finished) I start a thread in the DLL with

    CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, THREAD_FunctionX, & tmpTFP, NULL);

    with "tmpTFP" as an instance of type "TYPE_THREAD_FUNCTION_PARAMETERS":

    typedef struct
    {
    //
    int IntVal1;                // 1. Integer-Wert
    int IntVal2;                // 2. Integer-Wert
    int IntVal3;                // 3. Integer-Wert
    int IntVal4;                // 4. Integer-Wert
    int IntVal5;                // 5. Integer-Wert
    //
    int IntBuffer1 [32];            // 1. Integer-buffer (aktuell genugt einer)
    //
    Double DblVal1;                // 1. Double-value
    Double DblVal2;                // 2. Double-value
    Double DblVal3;                // 3. Double-value
    Double DblVal4;                // 4. Double-value
    Double DblVal5;                // 5. Double-value
    //
    char CharVal1;                // 1. (Single)- Tank-Wert
    char CharVal2;                // 2. (Single)- Tank-Wert
    char CharVal3;                // 3. (Single)- Tank-Wert
    char CharVal4;                // 4. (Single)- Tank-Wert
    char CharVal5;                // 5. (Single)- Tank-Wert
    //
    char CharBuffer1 [1024];        // 1. Char buffer (akutell einer genugt)
    //
    } TYPE_THREAD_FUNCTION_PARAMETERS;

    In the GUI-user program - I get fast by default-return value of the thread start function.

    Then I asked the DLL (some global state variables are used for this) when it is finished.

    According to the map-controller (RS232) contacted the waiting time depends on the 'mood' of the controller card.

    In the DLL-mark of the GUI-user-program routine now everything works fine - without using "SetCtrlVal!"

    In my GUI, there is a text box of the info/comment for messages. If I do a few outputs user using 'SetCtrlVal' I always errors, caused by the false "TYPE_THREAD_FUNCTION_PARAMETERS"-values in the service of thread. "» If I set a breakpoint at the beginning thread-function I see mostly erroneous values in my transfer structure variables. If I put a breakpoint in the thread-function-calling 'CmtScheduleThreadPoolFunction (...)"and at the beginning of the thread values are (mostly) correct!

    I tried several and different things - but:

    If I ONLY (!)  Commenting on the (!) of a line with "SetCtrlVal", the program works, all States are asked out of the DLL.

    If I replace the "SetCtrlVal" with a written record-file function clean everything works fine and after completing the program I can look at the log file and see all the user information. BUT with 'SetCtrlVal' instead or set or (...) it does not work.

    My description is maybe not entirely clear, but believe me: only ONE line the «SetCtrlVal "line - should be commented out to let the program run properly!»

    Because if the line "SetCtrlVal"is program-user-GUI, after the call to the thread in the DLL, the DLL-memory seems to be corrupted by the call "SetCtrlVal" in the user-GUI program.»

    Best regards

    F.

    There may be a problem in your structure that your variable is set.

    You said that, after the address of the variable in the thread function the appellant one ends. Now, as you can read help each value passed in parameter threadFunctionData of the layed function must point to an area of memory that persist when the fuction is running: If your variable is defined at the level of the functions it is not valid when the thread runs since the appellant finished and released its local memory.

    Your approach with a global variable is a valid alternative, but if it is the solution, you will find data passed to the thread function must be valid for all his life.

  • Battle of abnormal termination of the program 2142 (bf2142)

    I have recently upgraded to Windows 7 Beta, I have had no problems running all my favorite games.  Once I've upgraded to Windows 7 Pro, I had some problems with games.  I'll stick to the subject and only discuss 2142.  After my Windows 7 Pro upgrade, I initially installed BF 2142 and new patches.  He played for a few days with no problems.  Then, I received the Microsoft Visual C++ Runtime Error "abnormal termination of the program."  I get this right after the splash screen for the program ends.  This is not a consistent error.  Sometimes, the game will run for days and then suddenly, without any installation or known Exchange I got the error once.  I tried rebooting, uninstall and reinstall the game, change the resolution options specified in the icon and other things.  Not really interested in blame it on the BONE or the game.  I just want to play my game on the system I built with consistency.    Really hope someone can help.  Thank you in advance!

    I suggest that you put your system in clean boot and see if the problem occurs.  With it being so random, it may be another program that is confilicting with BF2142.

    Mike - Engineer Support Microsoft Answers
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Not closed after the thread.sleep call dialog box

    Hello

    I am display the dialog box and then call thread.sleep (5000), after I called two alerts more dialogue. The problem is when it displays the first dialogue onclick of the button ok its not be closed and its second dialog box open automatically. you have no idea.

    Code example

    try {}

    Dialog.Alert ("HI");

    business logic

    }

    catch

    {

    Thread.Sleep (3000);

    Dialog.Alert ("Hello");

    }

    After the display "Hi", I'm not able to close this dialog box. I tried to put the Thread.sleep inside DMT invlodLater(), no luck

    Any idea?

    Not sure what you mean by there.

    If you want to encode a thread. Sleep (), or waiting for a similar block of code, you must be on the thread of events.  And you can not do without starting another Thread.

    Maybe this will help:

    http://supportforums.BlackBerry.com/T5/Java-development/what-is-the-event-thread/Ta-p/446865

  • Call Dialog.ask in the Thread Run method

    "in I want to call Dialog.alert and using following code but its exception to throw the wire.

    "Exception occurs java.lang.RuntimeException: pushModalScreen called by a thread of non-event."

    synchronized (Application.getEventLock ())

    {

    if (Dialog.ask ("catalog is obsolete. You want to keep it? ", choices, select, select [0])(==1)"

    {

    Run the required functionality

    }

    }

    pls help me

    I keep saying this, so forgive me of repeating myself, but:

    synchronized (Application.getEventLock ()) {}

    should only be used when nothing else will work for you or you make a very simple, very fast UI update.

    A Dialog.ask is not very fast!

    In this case, you have several options, but the most obvious solution is to ask the question before starting the Thread.  So, if that is your treatment

    Thread catUpdateThread = new Thread() {}

    public void run() {}

    Dialog.ask (...)

    Other treatments

    }

    }

    catUpdateThread.start ();

    What should do the same and works OK. :

    UiApplication.getUiApplication.invokelater (new Runnable() {}

    public void run() {}

    Dialog.ask (...)

    If (result == Yes) {}

    Thread catUpdateThread =...;

    catUpdateThread... Start();

    }

    }

    });

  • Client/server Push application: how to run the thread listening on basis of the necessity?

    Hello

    To receive the broadcast content from the server, a thread of listening to the need to run in the back ground on the BlackBerry.

    For a client application to receive the server put grows optimally updated, what is the best way?

    1. run the thread listening on the installation of the client application using auto-run on start up?

    What happens to the thread if there are reboot the device? The listener would start again?

    2. run the thread listening on the launch of the client application?

    (or)

    3. is there a way to run the thread to listen according to the need, when there is dissemination of the server, as some notification (called by server) to the client that there is dissemination of the server and the client then begins the listening thread?

    Please contribute your valuable and suggest most commonly followed and best practices.

    Kind regards

    Suresh.

    you don't know. If it's a good thing to do is another question.
    You can use an inboxlistener to receive an email or even a text message with a command to start the pushlistener. But why you want to do something like that? listening on a port, there's nothing that drains the battery.

  • MenuItems run() method that is called from the thread eventdispatching?

    Hello

    is it? I know that MenuItem itself extends thread, but I wonder why this method is called run() and finally and above all it would'nt be worse if this method would be called from a Thread.

    THX

    In fact the menu items are run on the thread of the event. You can see this by creating a menu item long-term. The menu will not close and will not refresh the screen.

  • Stop the thread

    Hi all

    I have a strange problem with the wire

    I'm doing some tasks to the wire and I want to stop the thread when closing, but I couldn't do that

    I use myThread.interrupt () but it will not deliver the thread doesn't always works, even when the screen closed.

    Here is an example of what I'm doing

    workingThread = new Thread (new Runnable()
    {
    public void run()
    {
    Try
    {

    getdatafromWeb();

    for (int i = 0; i)<>
    {
    final byte [] imageData = getImage (currentUrl);
    UiApplication.getUiApplication () .invokeAndWait (new Runnable()
    {
    public void run()
    {
    if(ImageData!=null)
    {
    currentScreen.add (new BitmapField (...));

    }
    }

    });
    }

    }

    catch (System.Exception e)
    {
    }
                         
    }
    });
    workingThread.start ();

    You can put a Boolean value in your county that interrupts if set to false.

  • The thread timeout

    Hello, is it possible to set the time-out for the thread? Or kill the thread if it runs longer than expected? If so, how?  Thank you

    "Is it possible to set the time-out for the thread?

    Not that I know of.

    "Or kill the thread if it runs longer than expected? If so, how? »

    Start another Thread or a timer, which gives a reference to the Thread to be killed.  When the time expires to check to see if the Thread has finished (isAlive()) and if so try to kill him.  How do you kill, this will depend on what he does, you can try Thread.interrupt () but I'm not sure that this will break the connection http for example.

Maybe you are looking for