Pause timer if user presses up or down key, resume when they don't

I am running a routine set of activities with a timer in C#.
public MainWindow()
RefreshTimer();
public void RefreshTimer()
var refreshTimer = new Timer();
refreshTimer.Elapsed += (sender, e) => RefreshPlotList(sender, e);
refreshTimer.Elapsed += (sender, e) => RefreshWatchList(sender, e);
refreshTimer.Interval = 2000;
refreshTimer.Enabled = true;
How would I pause the timer if the user presses the up or down key, and then resume it after the key action is done?

Sorry for the slow reply ... I got busy with weekend stuff.  ;0)
I'm assuming that the RefreshTimer() is only called once from the MainWindow (I should also mention that you forgot to start the Timer). And that's really all you need for that (create and start it once). However, I'd make the refreshTimer variable a class
member/field, instead of local to the RefreshTimer() method. That way, you can access it from the KeyUp and KeyDown event handlers and don't even need the _upDownKeyIsPressed variable.  Like this:
private System.Timers.Timer refreshTimer;
public MainWindow()
RefreshTimer();
public void RefreshTimer()
this.refreshTimer = new Timer();
refreshTimer.Elapsed += (sender, e) => RefreshPlotList(sender, e);
refreshTimer.Elapsed += (sender, e) => RefreshWatchList(sender, e);
refreshTimer.Interval = 2000;
refreshTimer.Start();
private void KeyUpPress(object sender, KeyEventArgs e)
if (e.Key == Key.Up || e.Key == Key.Down)
this.refreshTimer.Enabled = true;
Console.WriteLine(_upDownKeyIsPressed.ToString());
private void KeyDownPress(object sender, KeyEventArgs e)
if (e.Key == Key.Up || e.Key == Key.Down)
this.refreshTimer.Enabled = false;
Console.WriteLine(_upDownKeyIsPressed.ToString());
~~Bonnie DeWitt [C# MVP]
http://geek-goddess-bonnie.blogspot.com

Similar Messages

  • Want to close  JInternalFrame when user press OR release "Esc" key.

    i want to close JInternalFrame when user press OR release "Esc" key.
    i am trying that
    but nothing print on console
    public class IFTest extends javax.swing.JInternalFrame {
        public IFTest() {
            initComponents();
        private void initComponents() {
            setClosable(true);
            addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    formKeyPressed(evt);
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    formKeyReleased(evt);
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    formKeyTyped(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 394, Short.MAX_VALUE)
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 278, Short.MAX_VALUE)
            pack();
        private void formKeyPressed(java.awt.event.KeyEvent evt) {
            System.out.println("formKeyPressed");
        private void formKeyReleased(java.awt.event.KeyEvent evt) {
           System.out.println("formKeyReleased");
        private void formKeyTyped(java.awt.event.KeyEvent evt) {
           System.out.println("formKeyTyped");
    }

    i don ti thanks
    public class IFTest extends javax.swing.JInternalFrame {
        public IFTest() {
            initComponents();
             this.getActionMap().put("test", new AbstractAction(){
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Escape Pressed");
            InputMap map = this.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
            KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
            map.put(stroke,"test");
        private void initComponents() {
            setClosable(true);
            addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    formKeyPressed(evt);
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    formKeyReleased(evt);
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    formKeyTyped(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 394, Short.MAX_VALUE)
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 278, Short.MAX_VALUE)
            pack();
        private void formKeyPressed(java.awt.event.KeyEvent evt) {
            System.out.println("formKeyPressed");
        private void formKeyReleased(java.awt.event.KeyEvent evt) {
           System.out.println("formKeyReleased");
        private void formKeyTyped(java.awt.event.KeyEvent evt) {
           System.out.println("formKeyTyped");
    }

  • HT203167 I downloaded two movies from itunes at the same time (both free digital copies from a dvd) and when they finished downloading... they disappeared. I've not been able to re-download them or find them.. anywhere. Any suggestions for tracking them d

    I downloaded two movies from itunes at the same time (both free digital copies from a dvd) and when they finished downloading... they disappeared. I've not been able to re-download them or find them.. anywhere. Any suggestions for tracking them down?

    If you downloaded them on your computer's iTunes then they should have gone into the Movies part of your iTunes library, if on a device (iPad, iPhone or iPod Touch) then into the Videos app - they haven't appeared there ?
    If you downloaded on your PC and they don't show in the Movies section then you could try searching for them by name (or part of their name) via windows explorer and see if that finds them. Or if you downloaded them on a device and they aren't in the Videos app then have you got a film age rating set in Settings > General > Restrictions that is hiding them, and if not can you find them via the device's spotlight search screen (swipe your first homescreen to the right) ?

  • How to apply "user configuration" of GPO of specific OU when they login on specific computers?

    For example:
    Only users belong to OU1 cannot access control panel when he log on to computer1 which belongs to OUA, how to do that with GPO?
    The users in OU1 CAN access control panel when they log on the computers which NOT in OUA, and users who are not belong to OU1 CAN access control panel when log on  computer1.
     thanks.

    It sounds like you need loopback enabled. Loopback allows you to apply user side settings to a computer.
    http://deployhappiness.com/loopback-policy-how-a-computer-gets-a-transgender-operation/
    http://deployhappiness.com/questions-about-loopback-policy-processing/
    If my answer helped you, check out my blog:
    Deploy Happiness

  • Some users are having access to all mailboxes when they configure thier outlook

    for 7 users the get access to all mailboxes so when they configure their outlook profile they get about 700 mailbox so outlook hangs this happens with new created users the same 7 users will get access to them as will 
    i tired this
    Get-Mailbox | Remove-MailboxPermission -User Administrator -AccessRights Fullaccess -InheritanceType all
    nut then i got this
    An inherited access control entry has been specified CreateChild ControlType Allow
    then o tried removing from the DB level
    Remove-Adpermission "DB" -user "jobs" -extendedrights Receive-As
    Remove-Adpermission "DB" -user "jobs" -extendedrights send-as
    Remove-Adpermission "DB" -user "jobs" -extendedright ms-Exch-Store-Admin
    but stilll the same

    hi thank you, looks i need some more detail on how to do this
    i saved the lines on a .ps1 file tried to run it on exchange and i got the below , can you illustrate more how to do this
    The operation couldn't be performed because object 'sharedmailbox' couldn't be found on 'DC.mydomain.com'.
        + CategoryInfo          : InvalidData: (:) [Get-MailboxPermission], ManagementObjectNotFoundException
        + FullyQualifiedErrorId : E61E2EBE,Microsoft.Exchange.Management.RecipientTasks.GetMailboxPermission
    Cannot bind argument to parameter 'Instance' because it is null.
        + CategoryInfo          : InvalidData: (:) [Remove-MailboxPermission], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-MailboxPermission
    Cannot bind argument to parameter 'Identity' because it is null.
        + CategoryInfo          : InvalidData: (:) [Add-MailboxPermission], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-MailboxPermission

  • Users are being prompted for Admin credentials when they attempt to print.

    Hello!  I am a Tech assistant at a public school and we have run into an issue with our students and their MacBooks & MacBook Pros.
    Whenever our students attempt to print to any printer in their school building they are prompted for administrator credentials.  I have attached examples of the message they are getting:
    We are not sure how to go about tackling this issue.  We are getting this message on both MacBooks and MacBook Pros.  They are all running Mountain Lion.  Last year they were all on Lion and we never had this issue.  Could this possibly be a known issue with Mountain Lion???  Once we type in the administrator credentials for the students they are able to print from then on.  Many of the students are also seeing this message when they try to print at their homes.  It seems to have something to do with printing permissions but we're just not sure.  Any help would be very much appreciated!
    Thanks!

    You used Workgroup Manager, Profile Manager, or Parental Controls to restrict users from printing or adding a print queue. Remove or modify those restrictions the same way.

  • In iPlanet Web Proxy Server 3.6 on Win2000, how do I turn on authentication?  I want to force users to enter an id and pw when they go thru the proxy to websites out on the net. Thanks

     

    Mal,
    You'll need to point to some user database, either the local db on Proxy or an ldap server. The ldap server is the best choice as the local db just stores users in a flat file and becomes unreliable after 1000 entries.
    To enable authentication, manage the proxy server instance and navigate to Restrict Access.
    From there, turn on access control, and click on the Permissions button. This will open up a new window to allow you to setup your access control rules and restrictions. When you're done, click on Done, apply your changes and restart the proxy server and you should be on your way.

  • Users able to see documents via URL when they cannot see the folder containing them?

    I took an AD group out of the permissions list for a folder in a document library. Then I ran an incremental search.
    Now, users in that group cannot see the folder (correct behavior!).
    Users in that group do not find documents in that folder when performing a site search (correct behavior!).
    BUT, users in that group CAN open a document in that folder by using the full URL to a document there, the full link.
    This seems like a security violation - how can the members of that removed group open a document in a library that they cannot even see?
    SP2010 Enterprise, SP1, Feb 2014 CU on Windows Server 2008 R2
    Win7 clients with IE10
    I have reviewed the groups in use and the permissions lists where they are used and don't see any source of "leakage".
    Any ideas why this might be happening and how to fix it?

    Hi,
    Based on your description, my understanding is that the user without permission can see a document in a folder by using the full URL to a document.
    I have followed your description to do a test, but I can’t reproduce your problem.
    My 
    suggestion is that:
    Sign in your site with a user who has full control 
    permission to the site, and go to  the documents in the folder and check whether the users in that group without permission to the folder have permissions to the documents.
    When users in that group use the full URL to a document , please check whether the current user is the user in that group without permission to a
    document in the folder. You can try a test in another computer.
    Please clear your browser Cache and then test again.
    If the issue still exists
     , please don’t hesitate to let me know.
    Best Regards
    Wendy Li
    TechNet Community Support

  • Why can't other computers open my photos from Iphoto or down load them? they don't show up as an icon.

    Why can't other computers open and/or download my photos when I email themfrom IPhoto? Have also tried making it a separate file on my desk; to no avail.
    It shows as an icon and jpeg when it goes out from my computer but they can't download it.
    They might see the photo imbedded in the emil but it doesn't appear as a downloadable icon.
    Thank you for your help.

    I think I can help. I use Mac but my secretary uses PC.
    Make a file on your desktop and name it "test"
    Go to iPhoto and click on a photo to send to this folder
    Go to file and choose "export"
    Pop up window - Kind: jpeg
    quality: maximum
    size: full
    click on export and choose the "test" folder you created on the desktop.
    You can now send any jpeg that you put in this folder from an email account by "attaching file" from within the email. If you have more than one jpeg, right click on the folder and choose "compress file"

  • IPhone 4 just upgraded to 4.2.9.  First time I plugged headphones in, phone doesn't recognize when they are removed.  I have tried repeatedly plugging/unplugging headphones, but still no speaker volume.  Any ideas?

    I have recently upgraded my iPhone 4 to OS 4.2.9.  After plugging in headphones, I can't get the speakers to work.  I have read a few articles online that suggest inserting and removing the headphone plug into the jack, but this hasn't worked.  Any ideas?

    Just read another article that suggested blowing compressed air in the port.  After trying this, the speakers were working again.

  • Headset volume down key problem with STH30

    Hello!
    I just bought a Sony STH30 Stereo Headset for my Xperia Z1.
    But when pressing the "Volume down" button on my headset, the key is hold for 5 to 10 seconds.
    This only happens on the Xperia Z1, it's working fine on other phones.
    It also works pretty fine when changing the volume of an active call - it only happens when trying to lower the volume of the phone or music.
    Greetings from germany,
    Daniel

    i have the same problem with my zenfone 5, 3 key is notworking, when i press pause/play my music player is pause and don't play again until i'm reset my phone, as the same volume up / down is nerver work, but it's work fine on samsung, sony devices ( i'm not try on Xperia Z1 )
    Please tell me another way to use the three button, i have try "Headset Button Controller" app, "Smart key " app by Sony, but all is missing something like this:
    - 1 click play / pause button to play / pause: OK
    - 2 click play / pause button to next : OK
    - 3 click play / pause button to previous : OK
    - Volume Up / Down key : not working.
    Please advices.
    thanks.

  • No Page Down key

    Hello, please advise if this post is in the wrong forum. I have been using a Mac Mini at work together with an Apple keyboard model A1242. In reading PDF documents I would like to scroll by page, but the help says just press the Page Down key, which this keyboard does not have. Is there a shortcut for this or is it just not possible? If so, is that info in Help somewhere? TIA.

    Thanks, too bad I couldn't find that in the Help. I also noticed that fn-down arrow does the same thing. Cheers.

  • Small black squares appear/disappear when I used the down key

    Small black squares appear/disappear when I used the down key-particulary when on FB, but also at other times

    No, there is no yellow star on any of the entries. Each entry has the site's (or company's) logo, as well as the name of the site and URL. There is nothing more in each entry.

  • PLEASE help me!!! I,ve been all over looking for help/store or whatever to down load adobe flash player to open a certain website.  I need that app or something similar. I am a first time iPad user and not that swift on a computer either

    Please!!
    help me down load adobe flash player or something similar for my iPad. I want to open a certain website and it's required. I don't know where to go. i am a first time iPad user and not to swift on a computer either. Thank you

    Allan Eckert wrote:
    You are going to have to get Steve Jobs to change his opinion about Flash which will be like getting a Baptist to drink beer, next to impossible.
    Allan
    Funny you mentioned that analogy... because John the Baptist was a heavy drinker... (could steve jobs be secretly accessing flash content on his ipad?)

  • How do I generate a pulse with a user specified puse duration, down time and repitition, and then out put to a graph?

    How do I generate a pulse with a user specified puse duration, down time and repitition, and then out put to a graph and then to daq ports? 
    I used lab view in engineering class, but that was the extent of my usage and after fiddling around in lab view and looking on the web looking for solution, I could not produce desired results.  My professor wants me to produce something that will output a pulse for a specified duration, then downtime for another specified duration and then repeat the process a specified amount of times.  
    I am using labview version 7.1
    Thanks in advance.

    Hello,
    Are you using hardware (DAQ card) to generate this pulse or are you planning on doing this all in software.  If you have a DAQ card in LabVIEW you can go to Help » Find Examples and then select Hardware Input and Output » DAQmx » Generating Digital Pulses » Gen Dig Pulse Train-Finite.vi.  This will use a counter from your DAQ card to generate a finite number of pulses at a specified frequency and duty cycle.  Give this a try, or let me know if you are not using hardware, and we can figure something else out.
    Regards,

Maybe you are looking for

  • BE on MCS v7 migrate to BE6000 on UCS

    I have a client who has a 100 single MCS server based Business edition running version 7. Currently they are covered under UCCS/ESW nearing the end of this 3 year agreement. What is the correct migration path to take them from V7 to BE6k on UCS.  Loo

  • Sap-workflow devep

    Scenario u2013 1) The Project Manager will change the status from Initial to Active in portal. 2)At this point a work item or a mail should be sent to different stakeholders (ie Sponsor  etc ) in his outlook for  Approval or rejection from his outloo

  • Periodic pauses when copying data

    I noticed that when I tired copying a couple dozen gigabytes to my Apple Xserve Raid (configured RAID 5 + Hotspare) that the status of the data transfer would pause periodically every 500MB-800MB or so, for a duration of approximately 8 seconds +/- 2

  • RegEX for a valid mysql table name

    Hi all, i'm trying to figure out a regular expression for a mysql table so i can check if the string is a valid mysql table name. I don't know exactly the valid characters for a mysql table name. does any one have an Idea ? thnx

  • User Exit at the time of MB1A mvt type 262

    Hi I want to introduce exit at the time Process Order reversal through MB1A with mvt. type 262. At this I require check reversal is not more than consumption qunatity. Please suggest any one. Regards ARK