Interrupting program execution

Hello, I want to interrupt/stop my program execution when a certain button is clicked. I want to implement the cancellation button in another GUI which is independent of the parent GUI that contains my running thread. However, when i invoke "Thread.currentThread().interrupt()" to cancel, it doesn't seem to work, and neither does "Thread.currentThread().stop()" of which I understand stop is deprecated. Any help will be appreciated.

call setEnabled(false) on the enclosing window. Maybe I'm over-simplifying things, but it could work in certain situations. For e.g.,
import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SetEnabledTest {
  private static void createAndShowUI() {
    final WindowOne winOne = new WindowOne();
    JFrame frame = new JFrame("SetEnabledTest");
    frame.getContentPane().add(winOne.getMainPanel());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        createAndShowUI();
class WindowOne {
  private static final String DISABLED = "Disabled";
  private static final String DISABLE = "Disable for 5 seconds";
  protected static final int DISABLE_TIME = 5000;
  private JPanel mainPanel = new JPanel();
  private JButton controllerBtn = new JButton(DISABLE);
  public WindowOne() {
    controllerBtn.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        final Window win = SwingUtilities.getWindowAncestor(mainPanel);
        if (controllerBtn.getText().equals(DISABLE)) {
          controllerBtn.setText(DISABLED);
          win.setEnabled(false);
          new Timer(DISABLE_TIME, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              win.setEnabled(true);
              controllerBtn.setText(DISABLE);
              ((Timer)e.getSource()).stop();
          }).start();
    JPanel bottomPanel = new JPanel();
    bottomPanel.add(controllerBtn);
    JPanel topPanel = new JPanel();
    topPanel.add(new JTextField(10));
    topPanel.add(new JButton("Button"));
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(topPanel, BorderLayout.NORTH);
    mainPanel.add(bottomPanel, BorderLayout.SOUTH);
  public void setEnabled(boolean enabled) {
    Window win = SwingUtilities.getWindowAncestor(mainPanel);
    win.setEnabled(enabled);
  public JPanel getMainPanel() {
    return mainPanel;
}Edited by: Encephalopathic on Mar 12, 2010 3:11 PM

Similar Messages

  • Interrupt program execution to get data and resume execution

    Hi everybody,
    Does somebody know how can I interrupt the execution of my program (main VI and all sub-VIs), display a dialog box, collect a given datum from the user, and resume execution?
    Best regards,
    Esteban

    On the other hand, dialogs in LabVIEW are inherently blocking anyway. What exactly are you trying to accomplish, and how much do you know about LabVIEW? Sounds like you might want to go through some of the online tutorials.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Cancel a C program execution or an external exe program execution on demand

    I have to trigger the execution of an exe call wait.exe
    I have to wait for the end of this wait.exe or to interrupt it if asked by a button
    What is the best technique to do this
    I try ti use the command exec.vi but I don't know how to interrupt the execution of the wait.exe i just launched
    Does anybody know the solution
    Thibaut

    the wait.exe is waiting for end of data acquisition
    this is not an open source program so I cannot introduce interrupt
    before the same exe was trigerred  and  on demand interrupted by a C program with the flowwing code::
     Attente de la fin de l'acquisition par la cde WAIT.EXE
                 ZeroMemory(&si,sizeof(si));                         si.cb=sizeof(si);
                 bRetour=CreateProcess(NULL,szCdeWait,  NULL,NULL,FALSE,DETACHED_PROCESS,NULL,NULL,&si,&pi);
                 if (bRetour==TRUE)
                                        // Test de l'etat du process WAIT.EXE jusqu'a ce qu'il soit terminé a moins que l'utilisateur n'arrête le scanning
                                         bArretScanning = FALSE;
                                       do
                                                   dwRetour = WaitForSingleObject(pi.hProcess,0);  // Test et retour immédiat
                                                   if(dwRetour == WAIT_OBJECT_0) break;            // Fin du process alors sortie du do-while
    // Test du bouton CANCEL de la boite de progression
                                                   if (DlgProgression.CheckCancelButton())
                                                               // Affichage de la boite de dialogue de confirmation
                                                               if (AfxMessageBox(_T("Voulez vous réellement arrêter le gamma scanning ?"),MB_YESNO)==IDYES)
                                                               // Indication de l'arret demandé par l'utilisateur
                                                               bArretScanning = TRUE;
    // Arret du process WAIT.EXE
                                                               Retour = TerminateProcess (pi.hProcess, 0);

  • Concurrent program execution Error

    i have genrated a simple report and copied to linux server,could any on help me how to resolve the error.Eventhough I was Getting the output.
    ERROR:
    Program exited with status 1
    Concurrent Manager encountered an error while running Oracle*Report for your concurrent request 4349601.
    Review your concurrent request log and/or report output file for more detailed information.

    I have copied the message from the logfile itself for complete reference,plz look in to the following error
    ERROR
    +-----------------------------
    | Starting concurrent program execution...
    +-----------------------------
    APPLLCSP Environment Variable set to :
    Current NLS_LANG and NLS_NUMERIC_CHARACTERS Environment Variables are :
    American_America.UTF8
    Enter Password:
    Report Builder: Release 10.1.2.0.2 - Production on Wed Jun 4 16:36:01 2008
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Start of log messages from FND_FILE
    End of log messages from FND_FILE
    Program exited with status 1
    Concurrent Manager encountered an error while running Oracle*Report for your concurrent request 4349601.
    Review your concurrent request log and/or report output file for more detailed information.
    Executing request completion options...
    Output is not being printed because:
    The print option has been disabled for this report.
    Finished executing request completion options.
    Concurrent request completed
    Current system time is 04-JUN-2008 16:36:02
    ---------------------------------------------------------------------------

  • Date format changes in the middle of a program execution

    In my C code I have a series of select statements.
    When I first get a session to the database I use the following command to set the date format
    alter session set nls_date_format = 'MM/DD/YYYY HH24:MI:SS'
    It works fine for a few queries. After a while during the program execution I see that the date format changes to 'DD-MON-YY' format. This results in a series of error in my code because I expect the date format to always be in the 'MM/DD/YYYY HH24:MI:SS' format.
    Any idea why the date format should change all of a sudden in the middle of the program execution.

    I second the idea that you should always use TO_DATE and TO_CHAR if you want to reliably convert between dates and strings.
    Without seeing your code, it is hard to say why your date format is changing, but the most likely reason is that you are changing users somewhere in the code. For example:
    SQL> show user
    USER is "OPS$ORACLE"
    SQL> SELECT sysdate FROM dual;
    SYSDATE
    11-JUL-2003
    SQL> ALTER SESSION SET nls_date_format='dd-Mon-yyyy hh24:mi:ss';
    Session altered.
    SQL> SELECT sysdate FROM dual;
    SYSDATE
    11-Jul-2003 10:15:12
    SQL> connect jtest/test
    Connected.
    SQL> SELECT sysdate FROM dual;
    SYSDATE
    11-JUL-2003TTFN
    John

  • Program execution during RIMODAC2..will it  always reach to cif user exit

    Hello ,
    We are implementing cif user exit for Purchase Order at R3 side to capture additional date field. So logic to capture additional date field is put in user exit CIFPUR01. We have  RIMODAC2  background job for Purchase order running on daily basis.
    if there is no change in standard Purchase Order objects. When RIMODAC2 is executed  for purchase order Integration models ..will  program execution still always reach to R3  user exit part of the program irrespective of if  any change in standard purchase order object has happened or not.
    Will appreciate your answer.
    Thank you
    Best Regards
    Nilesh Patil

    Nilesh,
    I am no longer sure I understand the question.
    RIMODAC2 activates the model.  Once a model is activated, if someone changes certain specific fields in an R/3 object, then these changes are sent to SCM, either immediately or via change pointers.  All this happens irrespective of IM userexits.
    If this same field in this same object is changed in R/3, and a userexit also has been implemented, the  userexit will execute according to its design,  performing whatever task it has been programmed to do.
    If you create and implement a userexit, it begins working at that moment in time that it is installed.  Data that flowed across 'yesterday' to SCM is not affected.  Data that flows across 'tomorrow' will be affected.  Data in R/3 will usually only flow across to SCM if there is some kind of triggering event, usually a database 'change' transaction (e.g., ME22N for POs) The mere act of installing a userexit will not generally affect existing data on either side.  The userexit only affects data that flows across the IM. Unchanged records in the R/3 database will generally not be sent to SCM by the IM, and will not be subject to userexit processing.
    It is not generally the responsibility of a functional consultant to explain the workings of a userexit to a technical consultant.  It is enough that the functional identifies the userexit, and specifies the business requirement in as much detail as possible.  The developer is then responsible for carrying out the coding.  Technicals are generally expected to be competent enough to determine from the userexit docs, and from the surrounding code, how a userexit works.  They can also raise a message to SAP.  In the end, it is all just ABAP, although userexit implementations can be quite challenging. SAP seldom provides enough details in their documentation.   Once the Technical has finalized the code, Functional and Technical together then perform unit testing, before passing the mods to users for integration testing.
    If your client's coders are unable to manage the task, perhaps they should engage your company to provide technical expertise, as well as functional expertise.
    Best Regards,
    DB49

  • Remote Program Execution

    Dear Sir,
    I have following problem and very desperately looking for the solution .
    I have 9ias installed on window-2000 server and on this machine JSP/Servlet is also running .
    There is another Unix server also having Oracle 7.3.4 and Pro*C installed .
    My requirement is that on receiving a web client request , the invoked JSP must also execute a C program on the unix machine ( the execution of C program creates a text output file on the unix machine ) and after completion of C program execution the output text file must be available to JSP . As a final result of JSP execution this output text file must be returned to WEB Client .
    Please guide me how to go about this .
    Thanks and Regards
    B V Mittal

    Call your C program like this from your controller servlet
    Process p = Runtime.getRuntime().exec("c.exe");
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    Then read from your generated file and populate whatever you need into a bean.

  • Dialog Box simulation without interrupting program flow

    I'm developing data acquisition/control software and need to give the end
    user flexibility to change the file to which the acquired data is being
    saved during operations. In the past, users have been confused with a
    simple string control that specifies the data file path, so I would prefer
    to move to the popup/dialog box standard to windows. Unfortunately, calling
    a dialog box results in the stoppage of program flow for the caller until
    the dialog box is closed (even though there may be no apparent data flow
    from the popup VI.) and stopping the program flow is not an option for this
    control system (the computer is controlling pressure, temperature, flow
    rates, etc of a very expensive and sensitive bit of hardware, so halting the
    control function for an unknown length of time is unacceptable).
    I am looking for the best way to accomplish this under LabVIEW 6i.
    Using a VI class reference through VI Server, I can essentially detach the
    popup window from the base program execution, spawning a separate
    application and passing the relevant parameters through judicious use of
    global variables. If I call the subroutine via VI server with "Wait until
    done" attribute set to false, the appropriate VI appears, functions
    correctly, and terminates as expected. Unfortunately, it remains visible on
    the screen, an inactive application. I have the VI Properties -> Window
    Appearance -> Customize -> Show Front Panel When Called and the Close
    Afterwards if Originally Closed checkboxes checked on this popup VI. It
    seems that calls through VI Server trigger the "Originally Open" flag, so
    the window does not close as I had expected.
    The way I have found to get around this problem is to use VI Server to call
    an intermediate subroutine whose front panel is not displayed and whose sole
    purpose it to call the subroutine that calls the dialog box. This does what
    I wanted, essentially. When the user wants to change directories, they
    press a button that triggers a call to VI Server to open a separate
    application. This application's front panel is never displayed and only
    calls a sub-VI that performs all the actual work and ends when it is
    completed. As this sub-VI terminates, all visible traces of the subroutines
    disappear and I'm left with just the primary program executing, continuing
    to take and send control signals through this whole process.
    This seems a rather cumbersome way to get a custom dialog box on the screen
    without stopping the program flow of the caller, however. Is there a more
    efficient way to accomplish this?
    Wade C. Eckhoff
    [email protected]

    Wouldn't it be easier to use two parallel independent while loops in the
    main vi, with one taking care of acquisition and the other of user
    interaction.
    When the UI loop is temporarily 'halted' because of the dialogue box poping
    up, the acquiring loop continues without delay.
    Regards
    Harrie Boonen
    www.novonordisk.com
    "Default User" wrote in message
    news:[email protected]...
    > I'm developing data acquisition/control software and need to give the end
    > user flexibility to change the file to which the acquired data is being
    > saved during operations. In the past, users have been confused with a
    > simple string control that specifies the data file path, so I would prefer
    > to move to the popup/dialog box standard to windows. Unfortunately,
    calling
    > a dialog box results in the stoppage of program flow for the caller until
    > the dialog box is closed (even though there may be no apparent data flow
    > from the popup VI.) and stopping the program flow is not an option for
    this
    > control system (the computer is controlling pressure, temperature, flow
    > rates, etc of a very expensive and sensitive bit of hardware, so halting
    the
    > control function for an unknown length of time is unacceptable).
    >
    > I am looking for the best way to accomplish this under LabVIEW 6i.
    >
    > Using a VI class reference through VI Server, I can essentially detach the
    > popup window from the base program execution, spawning a separate
    > application and passing the relevant parameters through judicious use of
    > global variables. If I call the subroutine via VI server with "Wait until
    > done" attribute set to false, the appropriate VI appears, functions
    > correctly, and terminates as expected. Unfortunately, it remains visible
    on
    > the screen, an inactive application. I have the VI Properties -> Window
    > Appearance -> Customize -> Show Front Panel When Called and the Close
    > Afterwards if Originally Closed checkboxes checked on this popup VI. It
    > seems that calls through VI Server trigger the "Originally Open" flag, so
    > the window does not close as I had expected.
    >
    > The way I have found to get around this problem is to use VI Server to
    call
    > an intermediate subroutine whose front panel is not displayed and whose
    sole
    > purpose it to call the subroutine that calls the dialog box. This does
    what
    > I wanted, essentially. When the user wants to change directories, they
    > press a button that triggers a call to VI Server to open a separate
    > application. This application's front panel is never displayed and only
    > calls a sub-VI that performs all the actual work and ends when it is
    > completed. As this sub-VI terminates, all visible traces of the
    subroutines
    > disappear and I'm left with just the primary program executing, continuing
    > to take and send control signals through this whole process.
    >
    > This seems a rather cumbersome way to get a custom dialog box on the
    screen
    > without stopping the program flow of the caller, however. Is there a more
    > efficient way to accomplish this?
    >
    >
    > Wade C. Eckhoff
    > [email protected]
    >
    >
    >

  • How do I insert or delete a row in tree during program execution ?

    Trying to understand how to edit/modify a tree control during program execution, specifically if I want to add a row or delete a row.
    Thanks

    Hi dwjef,
                 Go through this.I think by going through this you we will get an idea of how to achieve what you are trying.
                 https://decibel.ni.com/content/docs/DOC-20747
    Thanks as kudos only

  • How do I pinpoint the program execution?

    Hi all,
    I am wondering how to pinpoint the program's execution point?  I have a problem with all of the loops not stopping properly.  I hit the "Hilight Program execution" and it went to one loop, that is, it appeared greyed out, but I can't figure out which case it's stuck in.  Is there a way to find the exact *point* of execution?
    Thanks,
    Jason

    You can use breakpoints. The program will pause as soon as it hit the breakpoint. To add breakpoints, right-click in the place where you want it and set it. You can also set probes. The probes activate as soon as the information is available. Then you can be creative with the highlight execution, breakpoints and probes. You can have a fairly good idea on how your program is executing.
    Otherwise, try posting your code or an image of your code so we can try to figure out what is going on.
    www.vartortech.com

  • Compiling .java files during program execution.

    I have a program that read events in from a file and creates custom Event objects (which extend Thread) from this information, and then later the events are activated depending on the timing information that was provided in the file. Everything works great however, I would like to add the ability to include custom Events in the file that the events are read from. I would like the program to take that java code information and produce a class file that can be used during the programs execution. What classes can help me do this and are there any examples that anybody knows of, of something like this?

    I wonder if anyone has ever tried to do this before...
    http://onesearch.sun.com/search/developers/index.jsp?col=devforums&qp_name=Java+Programming&qp=forum%3A31&qt=dynamic+compilation+compile+runtime

  • Automatic program execution in the destination system.

    SAP allows to include "special objects" into a transport
    request which cause automatic program execution in the destinationsystem.
    Can anybody let me know how can I do that?

    Hi,
    Do you mean installing/executing some program automatically
    on user machine i.e. presentation system.
    If yes, then following link will help you, see last section Installing the control
    in which one setup file which is already uploaded to SAP Web Repository is downloded to presentation system and then executed on user machine to install the program.
    Using .Net Windows Controls in the ABAP Control Framework
    Regards,
    Vishal

  • Error out the ABAP program execution

    I have an ABAP program which transfers data from a file to a database table thru function module in packages of 50,000 records.
    Upon the successful completion of this ABAP program, I start dependent processes.
    Sometimes the function module does not transfer the data and returns the exception back to the ABAP program - which is an expected scenario. Currently when ever an exception is received in the function module, I stop the ABAP program with a STOP statement.
    The ABAP program stops, which meets my first objective. But what happens is, if you look at the job log --> it is Completed in terms of program execution and the dependent processes automatically start - which is not meeting my second objective.
    My second objective is to force the ABAP program to error out in such a way that .........
    1) The program execution is stopped
    2) If I look at the job log it should not be Completed (I am looking for something like Cancelled so that the dependent process do not get started automatically)
    Is it possible to error out the ABAP program execution by raising an exception or something, so that when i look at the job log - it shows Cancelled and not Completed?
    Let me know if you have any questions.
    Thanks,
    RK.

    Adrian,
    Thanks - This is exactly what I was looking for, it works.
    For some reason Messages skipped my mind and I was looking at raising Exceptions
    Solution:
    if sy-subrc NE 0.
      message id 'abc' type 'E' number 000.
    endif.
    Thanks,
    RK.
    Edited by: RK on Jan 17, 2010 7:47 PM
    Edited by: RK on Jan 17, 2010 7:50 PM
    Edited by: RK on Jan 17, 2010 7:52 PM

  • How to pause program execution?

    I'm developing a board game. It has the Board class, Coin class and Dice class.
    The dice class has an animation to show the dice rolling. The coin class also has an animation to show the coin moving from start square to end square.
    When user clicks on the dice the sequence of steps that take place are -
    getRandomNumber();
    dice.roll();
    coin.move();
    But the problem I'm facing is even before the dice rolling animation stops, the coin moving animation begins.
    How can I pause the program execution so I can move to next line in program only when the animation in the previous is stopped?
    or How can I change the logic so that it goes as desired.

    Timelines (well, actually KeyFrames) have an action variable, where you can put a function doing whatever you need to do at the end of the key frame.
    So, you can make your coin to move at the end of the dice animation (ie. calling coinAnimation.play() in the action of the last key frame of diceAnimation).

  • STOP Program Execution

    Hiii Everyone,
    How to stop execution of a program depending on a condition.
    Depending on a condition given in program, i want to stop the rest program execution. Program execution should be stopped at BADI.
    Thanks in advance.
    Regards
    Sunil

    Hi,
       I think the best is to put a break-point inside the method and check if it's executed or not
    I think the best is to put a break-point inside the method and check if it's executed or not
    Regards
    Kiran Sure

Maybe you are looking for

  • Create an AP Invoice based on a Purchase Order using SDK

    Hi, What are the steps to create an AP Invoice based on a Purchase Order using DI API? Which methods of which objects to use and what parameters to pass? Thanks.

  • Linked image borders in CS3

    This must be simple to fix, but I cannot find the option... When I attach an anchor tag to an image it automatically assumes a blue border. Of course I can turn this off in properties by setting border=0 but would like to turn it off permanently. Non

  • Problems in SQL Connection from Java program to Oracle 8.1.7

    Hi, I am java program that connects to Oracle 8.1.7 . Client: java code on Windows 2000 Server: oracle 8.1.7 on Solaris Java code uses two types of Connection Pools. One Pool uses "thin" connections and other pool uses "OracleConnectionPoolDataSource

  • How to find unhidden tv shows on iTunes?

    I recently saw that I had hid some TV shows on iTunes, and I wanted to watch them, so I clicked 'unhide'.  I thought this would mean that they would reappear in my library.  However I can not find them. Does anyone have any ideas as to where I might

  • Setting components position..

    i have designed my frame with componets using null layout and the screen resolution as 800 * 600, and its working fine, but when i change my screen size say 640 * 480 the screen size becomes big and the buttons are going well down the screen, so how