Proper method to close a JFrame

What is the most apropriate way to perform an action to close a JFrame when a button is click, and return the resource to the system?
Thanks.

U can first display the Welcomeframe whatever method u want to use
i assume u have a Button in WelcomeFrame which will invoke the DataFrame
If you have the following button write it as follows
JButton myButton = new JButton("Show Data Frame");
MyActionEvent lMyActionEvent = new MyActionEvent();
myButton.addActionListener(lMyActionEvent);In the action event class write down the following
class MyActionEvent implements ActionListener{
     public void actionPerformed(ActionEvent e){
          JDataFrame fJDataFrame = new JDataFrame();
          //Show or display JDataFrame here u can also do that from within the JDataframe class
          //Here get any values from fJDataFrame.
          //Because they will be lost once the frame is disposed
     //Line No 1:
          fJDataFrame.dispose();
}In the JDataFrame class set the following property
mJFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);Let me tell u what will happen.
When the JDataFrame is invoked from the action listener MyActionEvent the execution will stop at the Line now 1:. Until the fJDataFrame closes. Once the control comes back dispose the frame. Meanwhile do what u want in the JDataFrame until it is visible. U can later close your WelcomeFrame
Hope this helps

Similar Messages

  • Proper Method for closing a VI?

    Hi there,
    I am a very inexperienced labview user, so this question may be a walk in the park for you pros. What is the proper method for closing a VI? I want a particular VI to close upon a certain occurence. When I use a property node to close the front panel, then an invoke node to abort the VI with a static reference. I sometimes get a message dialog in the upper left corner of the screen that says "Resetting VI: [Vi's name].vi" at which point labview freezes, and must be closed externally from the Windows task manager. I know that using the "abort" can leave certain references open, so I close these references upon completion of every cycle... What is the proper method of closing a VI?
    Thanks a bunch,
    Ryan

    Hi Ryan,
    The correct method for closing your VI is dependent on how you have chosen to
    open it.  Like Jhoskins, I think the LabVIEW community will better be able
    to assist you if you post what you've already tried.
    If you have tried to dynamically load your VI using a Call by Reference Node,
    you will need to use an Open VI Reference and a Close Reference.  Please
    take a look at the Dynamic Load Example from the NI Example Finder.  You
    can find this by searching for VI Server in the Example Finder. 
    I have attached a figure that shows this Open, Run, Close paradigm in the
    Dynamic Load Example.
    Message Edited by cphuong on 04-17-2007 10:43 AM
    Regards,
    Ching P.
    DAQ and Academic Hardware R&D
    National Instruments
    Attachments:
    Open_Run_Close.JPG ‏88 KB

  • What is the proper way to close all open sessions of a NI PXI-4110 for a given Device alias?

    I've found that, when programming the NI PXI-4110 that, if a the VI "niDCPower Initialize With Channels VI" (NI-DCPower pallette) is called with a device
    alias that all ready has one or more sessions open (due to an abort or other programming error) a device reference results from the reference out that has a (*) where "*" is post-fixed to the device reference where and is an integer starting that increments with each initialize call. In my clean up, I would like to close all open sessions. For example, let's said the device alias is "NIPower_1" in NI Max, and there are 5 open sessions; NIPower_1, NIPower_1 (1), NIPower_1 (2), NIPower_1 (3), and NIPower_1 (4). A simple initialize or reset (using niDCPower Initialize With Channels VI, or, niDCPower Initialize With Channels VI, etc.) What is the proper way to close all open sessions?
    Thanks in advance. Been struggleing with this for days!

    When you Initialize a session to a device that already has a session open, NI-DCPower closes the previous session and returns a new one. You can verify this very easily: try to use the first session after the second session was opened.
    Unfortunately, there is a small leak and that is what you encountered: the previous session remains registered with LabVIEW, since we unregister inside the Close VI and this was never called. So the name of the session still shows in the control like you noted: NIPower_1, NIPower_1 (1), NIPower_1 (2), NIPower_1 (3), and NIPower_1 (4), etc.
    There may be a way to iterate over the registered sessions, but I couldn't find it. However, you can unregister them by calling "IVI Delete Session". Look for it inside "niDCPower Close.vi". If you don't have the list of open sessions, but you have the device name, then you can just append (1), (2) and so forth and call "IVI Delete Session" in a loop. There's no problem calling it on sessions that were never added.
    However - I consider all this a hack. What you should do is write code that does not leak sessions. Anything you open, you should close. If you find yourself in a situation where there are a lot of leaked sessions during development, relaunching LabVIEW will clear it out. If relaunching LabVIEW is too much of an annoyance, then write a VI that does what I described above and run it when needed. You can even make it "smarter" by getting the names of all the NI-DCPower devices in your system using the System Configuration or niModInst APIs.
    Hope this helps.
    Marcos Kirsch
    Principal Software Engineer
    Core Modular Instruments Software
    National Instruments

  • Counting Tags - Proper Method

    QUESTION: Am I using proper method in my development of
    automatically tallied footnotes?
    BACKGROUND
    While exploring on the W3 CSS 2.1 website I stumbled on the
    contents property of the :before and :after pseudo tags. This led
    me to the counter( ) function, the counter-reset property, and the
    counter-increment property that led in turn to my creation of
    automated footnotes for a single webpage (see Sample Page below).
    Although very pleased with what I developed, it is probably far
    from original, and I am hoping that someone with more extensive
    background in the use of counters could shed some light on how my
    future might look using the method I have employed for the creation
    of footnotes.
    Both the HTML and CSS code for my sample page validate using
    the FireFox validation tool. All of the CSS code has been placed in
    the document's <head> tag.
    THE FUTURE
    What I envision as my future in this regard is the use of my
    counter to tally footnotes across serially linked webpages. Once
    this is achieved, I am hoping to tally and label figures, graphs,
    tables, pages, section titles and other vital document information
    across the same set of serially linked webpages with a different
    set of similarly created counting tags.
    SAMPLE PAGE
    http://homepage.mac.com/moogoonghwa/practice/CSS/countingTags2.html
    In addition to commenting on the way I have created footnotes
    in the sample document, any online reading suggestions in regard to
    my envisioned future would also be greatly appreciated.
    Roddy

    Hello,
    Counter-reset, Counter-increment, :before and :after aren't
    supported by IE
    currently.
    However, they are listed as one of the CSS Compliance
    upgrades in IE8 Beta
    2.
    In browsers that support it, the method is fine.
    Take care,
    Tim
    "kiusau" <[email protected]> wrote in
    message
    news:gpkd10$36b$[email protected]..
    >
    QUESTION: Am I using proper method in my development of
    > automatically
    > tallied footnotes?
    >
    >
    BACKGROUND
    > While exploring on the W3 CSS 2.1 website I stumbled on
    the contents
    > property
    > of the :before and :after pseudo tags. This led me to
    the counter( )
    > function,
    > the counter-reset property, and the counter-increment
    property that led in
    > turn
    > to my creation of automated footnotes for a single
    webpage (see Sample
    > Page
    > below). Although very pleased with what I developed, it
    is probably far
    > from
    > original, and I am hoping that someone with more
    extensive background in
    > the
    > use of counters could shed some light on how my future
    might look using
    > the
    > method I have employed for the creation of footnotes.
    >
    > Both the HTML and CSS code for my sample page validate
    using the FireFox
    > validation tool. All of the CSS code has been placed in
    the document's
    > <head>
    > tag.
    >
    >
    THE FUTURE
    > What I envision as my future in this regard is the use
    of my counter to
    > tally
    > footnotes across serially linked webpages. Once this is
    achieved, I am
    > hoping
    > to tally and label figures, graphs, tables, pages,
    section titles and
    > other
    > vital document information across the same set of
    serially linked webpages
    > with
    > a different set of similarly created counting tags.
    >
    >
    SAMPLE PAGE
    >
    http://homepage.mac.com/moogoonghwa/practice/CSS/countingTags2.html
    >
    > In addition to commenting on the way I have created
    footnotes in the
    > sample
    > document, any online reading suggestions in regard to my
    envisioned future
    > would also be greatly appreciated.
    >
    > Roddy
    >

  • Close a JFrame from a button?

    How do I close a JFrame using a JButton to trigger the event? I want to dispose of the frame.
    thanks

    I think this peace of code should do it for you:
    public class MyFrame extends JFrame{
    private MyFrame() {
    this.setTitle("MyFrame");
    Container contentPane = this.getContentPane();
    contentPane.setLayout(new BorderLayout());
    // Close the application using a JButton.
    JButton closeButton = new JButton("Close");
    closeButton.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    contentPane.add(closeButton, BorderLayout.SOUTH);
    // Close the application using the JFrame.
    this.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);

  • Best practice of re-use a method in constructing a JFrame

    Hello All,
    I constructed a Main JFrame with the help of following method:
         JPanel createYpanel(JLabel lbl, JComponent txt){
              JPanel pane = new JPanel();
              pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
              pane.add(lbl);
              pane.add(txt);
              return pane;
         }Now, I need the above method for constructing a Child JFrame.
    What is the best programming approach?
    (a) Create a different private JPanel createYpanel(...) {...} in the Child JFrame, although it is 100% the same as that in the Main JFrame.
    (b) Make the method in the Main JFrame as static
    static JPanel createYpanel(...) {...}, so that it can be accessed by the Child JFrame as Main.createYpanel(lblA, cmpA);(c) Keep the method in the Main JFrame as non-static, but create an instance of the Main JFrame in the Child JFrame to access the method, such as
    JFrame mn = new Main();
    mn.createYpanel(lblA, cmpA);(d) None of the above. Please give me a better approach.
    My best guess:
    option (c) is the worst, since it needs to instantiate a Main JFrame only for the purpose of accessing this method and option (a) is redundancy although it can be done quickly by copy and paste. However, I'm not sure whether making a method static for this purpose is the best approach. Can anyone confirm this?
    Thank you for your help.
    Edited by: Patrick_Stiady on Jul 11, 2009 2:13 AM

    What is the best programming approach?I'm always reluctant to qualify any programming technique as "the best" - many ways to skin the cat.
    But here's my preference.
    (b) Make the method in the Main JFrame as staticYes.
    This instance method (currently) doesn't use any state nor collaborator from the instance, only its arguments.
    So it can be static. Indeed it should be static, for the other reasons you mention (no need to create an artificial "MainFrame" instance).
    However, you could locate this method in another class (+PanelUtility+, PanelFactory, whatever). Letting it in MainFrame, and using it from ChildFrame introduces a dependency that may not be relevant (if MainFrame publishes nothing else of use to the ChildFrame).

  • Invoke a method when Close Window is clicked

    Hi,
    How do i invoke a method when "close window" on the global button bar is clicked.
    Can someone please help.
    Thanks in advance.
    Pavan
    Edited by: user12215240 on Feb 23, 2010 9:32 AM

    Is it possible to change the settings so that when the red 'close' button is clicked, the application will hide instead of closing?
    Applications don't "close," windows do. If you are just closing windows but not quitting applications that opened them, it is no wonder that there are hundreds of apps in the Dock.
    A few apps like System Preferences have only one window, so they automatically quit when you close that one window. Most apps do not do this: even after all their windows are closed, they remain running & thus show up in the Dock, in Activity Monitor, & so on. They each require a little (or sometimes more than a little) real memory reserved for their use to remain running -- this subtracts from what is available to do useful tasks, & will slow down your Mac when it results in too much virtual memory use.
    Thus, it is a good idea to quit applications you don't have an immediate need for, especially if they don't require long startup times. If you want easy access to select applications, create a folder & fill it with aliases to those apps, then drag that folder to the right side of the Dock, where it will create a stack. When opened, the stack will allow one click launching of those apps.

  • The method queueConnection.close() shuts down the broker.

    Hi All,
    I want to send and recieve messages in the same application. I'm using embedded broker, here's the brokerConfig.xml
    <beans>
        <broker>
            <connector>
                <serverTransport uri="vm://localhost" />
            </connector>
            <persistence>
                <vmPersistence/>
            </persistence>
        </broker>
    </beans>I send and receive messages in the separate classes and each one creates its own connection. In the sender class when I call the method queueConnection.close() it shuts down the broker.
    How can I keep the broker to recieve messages in the receiver class by it's own connection?
    Thanks in advance.

    Hi James,
    I'm guessing you're using ActiveMQ?Yes, ActiveMQ v. 3.2.1.
    >
    FWIW there's an online forum specifically to discuss
    ActiveMQ related issues here...
    http://forums.logicblaze.com/forums/show/1.page
    10x for link, I'll try it for the next time
    Which version are you using?
    Unless its a really old version I'm a little in the
    dark. The code to close the embedded broker only
    fires when there are no more connections open; so
    provided each class has its own connection you should
    be fine.
    Note could this be a timing issue? Are you closing
    the connection of the sender before the receiver
    creates its connection?You're right. I think the problem is just there. I didn't know that the broker will close when there are no more connections open.
    Another option is just to explicitly create a broker
    yourself in Java code; then you are in control of its
    lifecycle.
    There are examples here
    http://activemq.org/How+do+I+embed+a+Broker+inside+a+C
    onnection?refresh=110x a lot. I'll create the broker myself

  • Proper method for interactive video

    Hi.  It's been a while since I've used Flash/Actionscript, and I've been having trouble figuring out the proper way to do this.  I'm hoping someone here can outline the proper methods.
    Basically, I'm creating a Flash project where it will play a video, then at a certain point, stop and display some buttons, and then go to the appropriate video based on what button was pressed.  Sort of a choose your own adventure type of thing.
    Without knowing the current/ideal way of doing it, how I tried it was by having the first video (embedded into the project) on one layer, and at the end of that video, I have a stop()  on another (script) layer (on the last frame of the video in the timeline), and I had the buttons (which appear on top of the video) on another layer at that same frame.  So, in theory, it plays the video, hits the last frame, stops the timeline, and waits for one of the buttons to be clicked.  Each button triggers and gotoAndPlay(), which takes the timeline to one of the other two videos that are located one after the other, after the first video, on the same (video) layer.
    Problem is, I have a bit of a catch-22...  I was aware that there would be sync issues between the video and it's audio (addressed by doing the audio as Sync or something in the audio properties)... however, I was suprised to see that the video does not maintain sync with the other layers (script).   So, what happens is that it plays the video, but SEEMS to play it faster than the script layer, so it reaches the end of the video before reaching the (identical frame) location of the actionscript.  As a result, the video loops, and the stop() is hit sometime during the start of the second playing of the video.  The buttons act similar, appearing sometime AFTER the point in the video where they should.
    I had embedded the video with the assumption that this would give me hard sync between it and the timeline, since it's physically there in the timeline, and you can see the frame at which it ends... and I thought then putting a stop() on that frame (but on a different layer), would guarantee that the stop code gets hit at the same time the end of the video was.
    I've tried a number of things, like putting the actionscript code on the frame after the video on the same layer, figuring a single layer can't go out of sync with itself... but that didn't work either.
    Looking into it, I saw that one option was to not embed the video, but to have it reference an external file (which, supposedly, would result in no sync issues).  But, in doing that, I'm not aware of how the rest of the timeline would know when the video has reached certain spots of the video.
    I'm sure the proper method is entirely different from what I'm doing, but I'm not familiar with other methods.  I'm hoping someone can outline the proper procedures (in as much detail as possible, since I probably won't know about much of what you are explaining).
    Keep in mind, again that this is basically what I want to do:
    -Play video 1
    -Stop timeline, display buttons, wait for response
    -Based on which button is pressed, jump in the timeline to video 2 or 3 (...I'm assuming all the vids will be on one layer, one after the other, with a label at the start of each one)
    Hope you can help.  Thanks.

    Hi, kglad.  Conceptually, I understand, but I'm totally new to most of these things.  I've worked with actionscript and flash in general, but am still very green when it comes to things like event listeners and some of the more technical coding.
    I've been frustrated with the tutorial vids I've been finding, as they are often very generic (...5 minutes of video, only to show you how to load the component onto the stage, then point to a video).  But, I did finally find one that seemed to address more detail.  It's the ActionScript 3 Video Basics tutorial on gotoandlearn.com.  All very techy code, which goes right over my head, but at least it's seemingly usable and relevant.  I just don't like using coding/methods I don't fully understand, as then you are helpless if something goes wrong.
    In answer to your question, what I'm after (in more detail) is this:
    -A video plays (Intro video)
    -After that video, a looping video plays, with buttons (Scene selection thumbnails) on top of it (Selection menu with looping background)
    -Clicking on one of the scene thumbnails then goes to the scene player section
    -Scene plays, and when it reaches the end of the clip, two buttons appear, and it waits (parked on last frame of the video via a stop() command)
    -Pressing button A jumps the timeline ahead 2 frames to the A video (which is located right after the initial scene video, right after the stop()), and that video plays, and stops at the end (via another stop() command.
    -Pressing button B jumps the timeline ahead many frames (past that second A video, over to the B video, which is the third clip on the video timeline, consisting of the initial scene, the A clip, and now the B clip), plays that and stops.
    Now, I am 90% sure that the way I am currently doing this is inefficient, obsolete, and to anyone half-decent at Flash authoring, completely wrong... but it's the only way I currently know.
    I've done the above like this:
    Timeline has the first (Intro) video embedded, then the second (Scene Selection loop), with a label ('Loop') at the first frame, and a gotoAndPlay('Loop') on the last, with the graphics and code for the scene selection thumbnail buttons occupying the duration/span of that loop clip, on a different layer.
    I have a MovieScreen movieclip, which has a series of one frame movieclips within it.  Each of those movieclips is the full video of a scene.  Think of the MovieScreen mc as a sort of Jukebox, containing a series of 1 frame 'records' (those being a movieclip that contains the video of each scene).  Pressing one of the thumbnail Scene buttons in the Scene Selection simply moves the MovieScreen movieclip timeline to the appropriate 'record' (frame containing the appropriate movieclip that contains the scene you selected), and jumps the main timeline (via a gotoAndPlay()) out of that Scene Selection loop, to the next frame after it, which is a 'Selection made' clip (an exit animation), which plays, and then parks on the 'Play Scene' section.
    The Play Scene frame of the main timeline simplly contains the Moviescreen movieclip, which (at this point) has had its own timeline jumped to the appropriate 'record' (movieclip within it), and that movieclip plays.  This is my (probably laughably incorrect, yet functioning) method to have a global 'movie player' frame in the main timeline, but have it able to play any of the available videos, rather than having a moviescreen for each scene.
    Certainly, I'd assume there is a far better way to do this, most likely with pure actionscript, where the scenes are called up, and things are dynamically generated... but, again, I don't know how to do that sort of thing.
    My first attempt had me embedding the videos directly into the timeline, which had the benefit of having the clip literally there on the timelines, taking up the literal amount of frames, and being visible during the timeline editing.  Problem is, it wouldn't play in sync with the rest of the layers (which was a real surprise, as I assumed that the whole point of embedding it would be to lock it to the timeline).  So, my codes/graphics that were placed on other frames at the end of the video clip's timeline layer didn't trigger in sync with the end of the clip (...which still puzzles me).
    My second attempt had the videos being called on as external clips, but that also had its share of problems, plus without the clips physically on the timeline, I had no way to know when the clip ended (...assuming I was to have the actionscript/graphics on a particular frame in the timeline... which I suspect now is wrong thinking).
    My third attempt used the FLV component.  First of all, the videos where about half the size that they should have been, plus where positioned half off the screen.  Today, I managed to figure out how to remedy that, so that works.  However, I soon realized that when placed on the stage, the resulting element on the timeline was an infinite duration, and not representitive of the duration of the clip, like an embedded vid would be... So, again, I had the problem of how to know when the clip ended, and where to place the script/graphics in the timeline.
    Researching a bit more today, I see that you can read metadata from a clip, which may be relevant to triggering a stop() or a loop back or a gotoAndPlay()...although I'm not entirely sure how it would all work.  I couldn't see an obvious way to loop a clip (from the FLV Playback properties).  So, even though I suspect this is the proper way to be doing this, I'm completely lost on how to utilize it.
    As well, I've been reading that the current version of the FLV Playback component has an issue with seamless looping... in that it supposedly can't.  So, that's yet another problem.
    Sorry for the novel, but I wanted to give everyone the full info on what I'm doing and what troubles I'm facing here.  Sorry too for being green on this.  I'd be happy to watch/read some tutorials on this, but really haven't found anything that either addresses things more than just 'load it onto the stage and select the video location', or ones that are the opposite end of the spectrum, and are way over my head.

  • Beginner's query: How to call a method on close of a frame?

    Hi. I wrote a frame that inherits from JFrame. There I called *"setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)"* (more or less). I now wish that the frame would call a method when it closes.
    How can I define that? I assume some action listeners should be added, but I would appreciate a thorough reply.
    Thank you!!

    Could someone please explain to me the main difference between adapters and listeners? WindowListener is an interface, if you use it then you have to implement all its methos whether you use then or not while WindowAdapter is a class which implements WindowListener and provides empty implementations of all the methods in the listener, so basically by using windowAdapter you are avoiding
    the implementation of methods which you don't required.

  • Tomcat Server Closes with JFrame Application

    When I open my JFrame Application, and decide to close it this application of mine closes together with my tomcat server... I suspect is the "System.exit(0);" in my JFrame application that causes it.
    Can anyone tell me what I should do to my JFrame application so when I closes it, it will not close my Tomcat server at the same time.
    Thank You : )
    Regards,
    RainbowEnergies

    It probably is the System.exit(0); You should remove that.
    Tomcat is a container which essentially means it's a sort of "main program" that calls your servlets, JSP programs, etc. as "subroutines". When a subroutine calls "exit", the main program will shutdown.
    If you need the JFrame to "exit" when it's being run independently of Tomcat, move the System.exit() call to the "public static void main()" method. Tomcat will never call your class's "main" method, since it uses its own.

  • How to close a JFrame window without its obj ??

    Hi
    I have a pure standard alone java applocation. When app was run, a GUI window/class ( JFrame class ) was launched/new to show some message. After a while, I want to close this window. If I did not pass or save this window obj, can I close this window ?? If yse how to close? In other word, it is hard for me to save or pass this window obj. But I have to close this window later on. I plan to use some static variables or method so I can call any time and try to close this window later on, but I failed. Thanks for help
    gary

    Hi
    Thanks all response. I am sorry I forgot to mention I can't use System.exit(0) because the application has not finished. But window message has finished its function and it no long be used again. In other word, I want to close window only , not whole application. If you use System.exit(0), it will close whole application. Message window can be used only during a piece of time. Thanks
    gary

  • Proper way to close the scene

    In my application i am using multiple scenes for multiple windows. when the function is completed, I close the scene using stage stage.close() function. Its written in javadoc that close() function is same as setVisible(false). hence even if i close the stage the resources are not released. what is the proper procedure for it? Any suggestions will be helpful.

    Hello user,
    When ever you remove the scene the scene resource are not removed from the memory. After you close the stage the rest of the job is given to Garbage Collector of JVM. If you want to manually clear the Garbage. You can call this function.
    System.gc();Thanks.
    Narayan

  • What is the proper method for cleaning up EventWaitHandle?

    Hi all,
    I'm working on inter-process communication between applications running on the same machine. More specifically I have a primary application that is connected to multiple industrial machines collecting data from each.
    I want to create secondary applications that consume this data. I intend on using MemoryMappedFile to share the information. I've tested the MMF part and it works fine.
    I'm at the point where I want to notify the client applications when new data is available by using an EventWaitHandle. I create the handle as follows.
    handle = new EventWaitHandle(false, EventResetMode.AutoReset, ClientName);
    In the client application I use WaitOne inside a thread for the event notification. This too works well.
    private void MonitorForSignal()
    running = true;
    bool signaled;
    while (running)
    signaled = handle.WaitOne();
    if (signaled)
    if (!handle.SafeWaitHandle.IsClosed)
    //Do something
    I create the thread as follows:
    monitor = new Thread(MonitorForSignal);
    monitor.IsBackground = true;
    running = true;
    monitor.Start();
    My concern is that I may be creating an orphaned thread or a memory leak when I close the client application. So I implemented IDisposable in my client class and do the following.
    protected virtual void Dispose(bool disposing)
    if (disposing)
    // free managed resources
    // free native resources here if there are any
    running = false;
    handle.Close();
    handle.Dispose();
    monitor.Abort();
    I believe this does indeed free the resources, but I've read that Thread.Abort is "bad". Before I implemented IDisposable I did some testing in a couple of WinForm applications, one acting as the host and one as the client. I noticed that I could
    close the client and subsequently Set the EventWaitHandle in the host application and this line of code in the client would fire in the debugger.
    signaled = handle.WaitOne();
    This made me worry that I wasn't properly cleaning up my thread objects.
    Below is the entire client for reference. What I'm really asking is how do I properly clean up the MonitorForSignal thread and the EventWaitHandle in the client?
    public class ClientA : IDisposable
    bool running;
    string clientName;
    EventWaitHandle handle;
    Thread monitor;
    private void MonitorForSignal()
    running = true;
    bool signaled;
    while (running)
    signaled = handle.WaitOne();
    if (signaled)
    if (!handle.SafeWaitHandle.IsClosed)
    //Do something
    private void ProcessData()
    //Do Something
    public ClientA(string ClientName)
    if (ClientName == null || ClientName == string.Empty)
    throw new ArgumentException("Cannot be null or empty.", "ClientName");
    clientName = ClientName;
    handle = new EventWaitHandle(false, EventResetMode.AutoReset, ClientName);
    monitor = new Thread(MonitorForSignal);
    monitor.IsBackground = true;
    running = true;
    monitor.Start();
    #region IDispose
    ~ClientA()
    Dispose(false);
    public void Dispose()
    Dispose(true);
    GC.SuppressFinalize(this);
    protected virtual void Dispose(bool disposing)
    if (disposing)
    // free managed resources
    // free native resources here if there are any
    running = false;
    handle.Close();
    handle.Dispose();
    monitor.Abort();
    #endregion
    Regards,

    Hi Michael,
    Does this code cause the thread to spin?
    while (!handle.WaitOne())
    //TODO: Do work
    Thread.Sleep(1000);
    I was hoping not to spin thus the EventWaitHandle. As for the named handle, I am building multiple applications that need to have inter-process communication, all running on the same machine.
    I think I can update my class to use your recommendation for the dispose method, specifically using handle.Set
    However, I would update the MonitorForSignal as follows:
    bool _closing = false;
    private void MonitorForSignal()
    running = true;
    bool signaled;
    while (running)
    signaled = handle.WaitOne();
    if (signaled && !_closing )
    if (!handle.SafeWaitHandle.IsClosed)
    if (NewData != null)
    NewData();
    And the dispose as follows:
    protected virtual void Dispose(bool disposing)
    if (disposing && handle!=null)
    running = false;
    _closing = true;
    handle.Set();
    if (!monitor.Join(5000))
    monitor.Abort();
    monitor = null;
    handle.Dispose();
    handle = null;
    // free managed resources
    // free native resources here if there are any
    This allows me to skip over the "Do Work" part which should only be done when Signaled from another application. Your suggestion to use handle.Set() in the dispose method coupled with adding the bool _closing allows me to get past the EventWaitHandle
    and also skip the work when closing.
    Also by setting "running" to false in the dispose, the thread will naturally end after the wait handle has been set.
    Thanks for suggesting the Thread.Join, that does seem allot more graceful. When I tested these changes it was blazing fast. In the previous code when I called monitor.Abort the application would hang for about a second. 
    Do you think the changes capture the intent of your suggestions?
    Regards,

  • Inkove method after close window with unload

    Hi guys,
    I'm trying create a way the invoke a method in a BackingBean after close the window of browser for this I'm using the event unload of 'af:document'.
    I used the Frank's sample ( http://blogs.oracle.com/jdevotnharvest/entry/responding_to_the_page_unload_in_a_managed_bean ) but it doesn't work.
    Can anybody help me?
    I'm using JDeveloper 11.1.2.0.0
    This a part of my code :
    Page
    <f:view afterPhase="#{backingBeanScope.backing_mainPage.afterPhase}"
              beforePhase="#{backingBeanScope.backing_mainPage.beforePhase}">
        <af:document id="d1"
                binding="#{backingBeanScope.backing_mainPage.d1}"
                title="CTBC - Algar Telecom"
                smallIconSource="imgs/favicon.png imgs/favicon.ico"
                onunload="performUnloadEvent"
                clientComponent="true">
        <af:resource type="javascript">
                window.addEventListener('beforeunload', function (){performUnloadEvent()},false);
                function performUnloadEvent(){
                  var eventSource = AdfPage.PAGE.findComponentByAbsoluteId('d1');
                  var x = AdfCustomEvent.queue(eventSource,
                                               "handleOnUnload", {}, true);
                  var y = 0;
        </af:resource>
        <af:serverListener type="handleOnUnload" method="#{sessaoLogoff.onUnloadHandler}"/>
          <af:form id="f1" binding="#{backingBeanScope.backing_mainPage.f1}">
    .ManageBean
    public class ControlaLogoff {
        public void onUnloadHandler(ClientEvent clientEvent) {
            System.out.println("good bye");
    }Regards,
    Renan

    I just tested the code Frank provided (as is) and it worked for me. the only thing to mention is when I closed browser completely the bean isn't called. If I close the tab running the page all works as expected.
    I strong feeling is that you simply can't catch the event if someone closes the browser (or use task kill). So if that is what you need you are out of luck.
    Again, the other case works for me. So if it's not working for you I guess there is some kind of coding error in your app.
    Timo

Maybe you are looking for