logo
Tags down

shadow

How to create a 3 second timer in Bash?


By : Javier
Date : October 16 2020, 06:10 AM
it should still fix some issue I created a task manager for linux with shell script I need to refresh the task manager every 3 seconds I was thinking of using Timer function but got stuck , Replace
code :
init
while true;
do
  :
done
while true;
do
  init
  sleep 3s
done


Share : facebook icon twitter icon

create timer using list value and assign those timer to execute query in C#


By : user3574482
Date : March 29 2020, 07:55 AM
I wish this help you Since your error syas that No overload for method 'Timer' takes '4' arguments, I'm guessing that you are using System.Timers.Timer class, for which there is no constructor which takes 4 arguments.
As per your code, you need to use:
code :
System.Threading.Timer
using ThreadingTimer = System.Threading.Timer;
System.Threading.Timer = new System.Threading.Timer(TimerAction, dataValue, 1000, 0);

How do you create a more accurate timer in OpenLaszlo than the lz.Timer class that can pause and loop?


By : Milind
Date : March 29 2020, 07:55 AM
will be helpful for those in need The following OpenLaszlo timer class I designed will fire more accurately and also has a nice looping feature with pause and reset for ease of use. This code works in OpenLaszlo 4.9.0 SWF10 and DHTML run-times:
code :
<library>

  <!---
  Class: <loopingtimer>
  Extends: <node>

  This class is a looping timer that can be used to call a method to peform
  an action repeatedly after a specified number of milliseconds.

  Override the abstract method reactToTimeChange(theTime) to do something
  useful in your application, theTime will be the time elapsed since the
  timer's last firing, it will be close to the 'timer_resolution' set but
  will be off from about 47ms-78ms in FireFox 2 and 47ms-94ms in IE6
  (see note below for explanation).

  NOTE:

  This class originally used the LzTimer class but it was firing up to 256ms
  late, so this has been replaced with a setTimeout() method and embedded
  JavaScript which is more accurate, but still fires about 59ms late on
  average.

  For this reason the firing times of this class are approximate but will
  probably fire 47ms to 78ms (about 59ms) on average late. As a workaround
  for this problem the timer uses the system time to calculate how much time
  has actually elapsed since the last timer firing and passes the actual time
  elapsed ('theTime') in milliseconds to the abstract 'reactToTimeChange()'
  method.

  -->
  <class name="loopingtimer" extends="node">

    <switch>
      <when property="$as3">
        <passthrough>
          import flash.utils.setTimeout;
        </passthrough>
      </when>
    </switch>

    <!-- *** ATTRIBUTES *** -->

    <!-- Public Attributes -->

    <!---
    @param numnber timer_resolution: number of milliseconds between timer
    firings (default: 40ms)

    Note: OpenLaszlo seems to typically have a lower limit of 47-78
    milliseconds between firings, so setting below this may be useless.
    -->
    <attribute name="timer_resolution" type="number" value="40" />

    <!-- Private Attributes -->

    <!--- @keywords private -->
    <!---
    @param number formertime: used internally to calculate the number of
    elapsed milliseconds since playback was started
    -->
    <attribute name="formertime" type="number" value="0" />

    <!--- @keywords private -->
    <!---
    Used internally for tracking virtual current time in milliseconds
    for pause functionality.
    -->
    <attribute name="currenttime" type="number" value="0" />

    <!--- @keywords private -->
    <!--- @param string timer_state: 'PAUSED' | 'COUNTING' -->
    <attribute name="timer_state" type="string" value="PAUSED" />


    <!-- *** METHODS *** -->


    <!-- Public Methods -->


    <!--- @keywords abstract -->
    <!---
    ABSTRACT METHOD: overwrite to do something useful in your program

    @param number theTime: the time in milliseconds elapsed since playback
    was  started
    -->
    <method name="reactToTimeChange" args="theTime">
      if ($debug){
        Debug.write('WARNING: reactToTimeChange(): This is an abstract method that should be overridden to do something useful in your application');
        Debug.write('reactToTimeChange(): Time elapsed since last firing in milliseconds: '+theTime);
      }
    </method>

    <!--- Start Timer (Note: This will reset timer to 0) -->
    <method name="startTimer">
      this.setAttribute('timer_state', 'COUNTING');
      var now = new Date();
      var rawTime = now.getTime();
      this.setAttribute('formertime', rawTime);

      this.doForTime();
    </method>

    <!--- Pauses timer at current time -->
    <method name="pauseTimer">
      this.setAttribute('timer_state', 'PAUSED');
    </method>

    <!--- Resumes timer from time it is paused at -->
    <method name="unpauseTimer">
      this.setAttribute('timer_state', 'COUNTING');
      var now = new Date();
      var rawTime = now.getTime();
      this.setAttribute('formertime', rawTime-this.currenttime);
      this.repeat();
    </method>

    <!--- Stop Timer - stops timer and resets to 0  -->
    <method name="stopTimer">
      this.pauseTimer();
      this.resetTimer();
    </method>

    <!--- Resets Timer to 0 -->
    <method name="resetTimer">
      this.setAttribute('formertime', 0);
      this.setAttribute('currenttime', 0);
    </method>

    <!---
    Seeks to the given time in milliseconds.

    @param number(int) iTimeMs: the time to seek to
    -->
    <method name="seekToTime" args="iTimeMs">
      this.setAttribute('currenttime', Math.floor(iTimeMs));
    </method>

    <!-- Private Methods -->


    <!--- @keywords private -->
    <!---
    Called Internally By Timer

    @param number theTime: the actual time in milliseconds that has passed
    since the last timer firing (will usually be 16-100ms more than timer
    firing interval)
    -->
    <method name="doForTime">

      // Prevent Timer Incrementing When Paused
      if (this.timer_state == 'PAUSED')
        return;

      var now = new Date();

      var rawTime = now.getTime();

      if (this.formertime != 0)
        var currentTime = rawTime - this.formertime;

      this.setAttribute('currenttime', currentTime);

      // Call Abstract Method:
      this.reactToTimeChange(currentTime);

      this.repeat();

    </method>

    <!--- @keywords private -->
    <!---
    Used internally for timer looping.
    -->
    <method name="repeat">

      // This function uses an embedded JavaScript function which
      // can be called via the standard JavaScript setTimeout()
      // method which results in more accurate timer firing then the
      // standard OpenLaszlo LzTimer() class. LzTimer() fired up to
      // 256ms late, while setTimeout() usually fires from
      // only 47ms-78ms

      var f = function(){
        doForTime();
      }

      setTimeout(f, this.timer_resolution);
    </method>

  </class>

</library>

Trying to create an application to pick up text on a timer but files are in use and timer doesn't work


By : akim
Date : March 29 2020, 07:55 AM
may help you . Like the other answer said, you need to remove that line. You also need to create the file properly and dispose after (so that handles are released). Also, set your timer to something lower like 1000ms. I also created a boolean variable to check if the connection has been made before the file is read by the timer. Remember to check that your timer is enabled in the settings.
Here is the code:
code :
Imports System.IO

Public Class Form1

    Dim file_name As String
    Dim connected As Boolean

    Sub Chat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Sub Create_Server_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Create_Server.Click 'This is a button on the form that get the user to choose a location to save the Chat_Server.txt

        SaveFileDialog1.ShowDialog()    'Save the file
        'SaveFileDialog1.OpenFile()
        file_name = SaveFileDialog1.FileName()  'Get the file path
        SaveFileDialog1.Dispose()
        File.Create(file_name).Dispose()
        MsgBox("Server file made.")
        connected = True

    End Sub

    Sub Connect_Server_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect_Server.Click   'Another button on the form that gets the user to choose the Chat_Server.txt

        OpenFileDialog1.ShowDialog()    'Open the file
        file_name = OpenFileDialog1.FileName()
        Dim fileExists As Boolean   'Tests whether the file existx and whether it works or not
        fileExists = My.Computer.FileSystem.FileExists(file_name)
        If fileExists = True Then
            Try
                Server_Text.Text = My.Computer.FileSystem.ReadAllText(file_name)
            Catch ex As Exception
                MsgBox("Can't load the file. Try again.")
            End Try
        Else
            MsgBox("Chat can't seem to find the chat file. Make sure it is called Chat_Server.txt and it is on an accessible network.")
        End If

    End Sub

    Sub Server_Text_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Server_Text.TextChanged

        Server_Text.Text = My.Computer.FileSystem.ReadAllText(file_name)    'Places the text from Chat_Server.txt into the main textbox

    End Sub

    Sub Chat_Text_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chat_Text.TextChanged

        Server_Text.Text = My.Computer.FileSystem.ReadAllText(file_name)    'Places the text from Chat_Server.txt into the main textbox

    End Sub
    Sub Chat_Text_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Chat_Text.KeyUp   'Another textbox that holds the text that the user wants to send to the Chat_Server.txt

        If e.KeyCode = Keys.Enter Then  'When the user presses enter the send button is clicked
            Send.PerformClick()
            Chat_Text.Clear()
            Server_Text.Text = My.Computer.FileSystem.ReadAllText(file_name)    'Places the text from Chat_Server.txt into the main textbox
        End If

    End Sub

    Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send.Click

        My.Computer.FileSystem.WriteAllText(file_name, vbCrLf & Chat_Text.Text, True)   'When send button clicked, write all contents of Client_Text to the Chat_Server.txt
        Chat_Text.Clear()
        Server_Text.Text = My.Computer.FileSystem.ReadAllText(file_name)    'Places the text from Chat_Server.txt into the main textbox


    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        If connected Then
            Server_Text.Text = My.Computer.FileSystem.ReadAllText(file_name)    'Every 100 miliseconds, places the text from Chat_Server.txt into the main textbox
        End If

    End Sub
End Class

how to fire timer when create the timer inside block function?


By : Victoria
Date : March 29 2020, 07:55 AM
may help you . In your case, the variable timer_ is never keep, and you lose the pointer at the end block scope. With a property you have retain / release mechanism.
Try this :
code :
@interface Taxi_MainViewController : Taxi_BaseNavViewController
{

}

@property (nonatomic,retain) NSTimer* timer;

@end



[Taxi_do_order psg_place_orderWithMemberId:strMemberId_ orderStatus:K_orderStatus_open andCLLocationCoord:location.coordinate callback:^(NSInteger iOrderId){
        [Taxi_StatusView dismiss];
        if (iOrderId >=0)
        {
            isOrderExist = YES;
            [weakSelf_ showWaittingDriverAcceptView];
            self.timer =   [NSTimer scheduledTimerWithTimeInterval:2.0
                                                               target:weakSelf_
                                                             selector:@selector(actListen:)
                                                             userInfo:nil
                                                              repeats:YES];
        }else
            [weakSelf_ hideWaittingDriverAcceptView];
    }faile:^(){
        [Taxi_StatusView showLostNetWork];
    }];

Create Custom Windows Service Timer : Basically Add Name to Timer


By : LoadsFaster
Date : March 29 2020, 07:55 AM
I wish this help you Seems enumerating or identifying .net object by name (string) has growing popularity, especially in Visual Basic community. In my opinion this is wrong, .NET API suggest using Tag for all programmers requirement that framework hasn't
code :
Timer t1;
Timer t2;
...
t1.Tag = new MyAdditionalInfo("foo");
t2.Tag = new MyAdditionaInfo("bar");

.. or simply 
t1.Tag = "foo";
t2.Tag = "bar";
Related Posts Related Posts :
  • How to fix error "'recipe for target "doc/automake-1.14.1' failed" while building Xenomai
  • no module named numpy even after installing it
  • Breaking out of nested function loops in Bash
  • Does read/write blocked system call put the process in TASK_UNINTERRUPTIBLE or TASK_INTERRUPTIBLE state?
  • How does logrotate work when there are two process use the same file?
  • Got error while Mounting, error massage:"mount.nfs: remote share not in 'host:dir' format"
  • GitLab-Runner "listen_address not defined" error
  • Linux device driver for a gps module
  • Command for printing part of a String?
  • How to make the query work in linux server?
  • How to enable CONFIG_RT_GROUP_SCHED in Ubuntu to make it RT
  • How to remove a file called * (asterisk) without using quotations?
  • Pipe stdout to with multiple lines to individual files
  • How to use case to identify a specific pattern in BASH script
  • numeric variable in egrep regular expression bash script
  • How to make find . -name "*.txt" | xargs grep "text" to work with filename with spaces
  • sed only print substring in a string
  • How can I use Bash to contract/shrink a set of values
  • DBD-Oracle (1.74 or 1.76) with oracle instantclient 11.2 on win10 wsl ubuntu
  • Bash command with pipe not working in crontab
  • Why does calling the C abort() function from an x86_64 assembly function lead to segmentation fault (SIGSEGV) instead of
  • Passing commandline argument to qml
  • How to speed up grep/awk command?
  • Errors while execute 'make' command, debian
  • Get a tag value in multi line XML using shell script
  • C can I open a directory's files using open dir in an alphabetical order?
  • Getopts default case bash script
  • Grep using a regular expression and capturing using groups
  • Measuring temperature while benchmarking on Linux
  • xm64 fills my processor resource in Linux Mageia 6
  • How to add verbosity option to control script output?
  • How to loop through an output and format the result into a new report?
  • Homework: Trying to calculate Easter using arithmetic evaluations
  • How to extract log using bash script between a date / time and another
  • Can ack/ag/grep print function name?
  • Can't realize alias/substitution function for my .bashrc
  • How to prevent changes to the underlying file after mmap()-ing a file from being visible to my program?
  • OpenJDK9 Missing in Alpine Linux
  • Insert data into database using sqlldr in coldfusion
  • Atomic read and truncate of file in linux
  • Zip files within the directory without file extensions
  • The sort command in linux does not work "correctly"
  • Linux command to delete all the files older than the latest modified file/s
  • How to write a custom device registration function for custom device such as RTC or ADC etc.?
  • Remove the first capitalized word after a period
  • Adding a security feature to the ssh login
  • How to merge column output to the end of a row in the previous column?
  • why '~' tilde directory is created automatically in home directory on AWS EC2 instance
  • How to read a file using cat with Perl -e parameters?
  • Run script skipping files
  • How to trap exit (ctrl+c) signal in Makefile?
  • A working linux kernel + gem5 config for FS boot up in x86 SMP
  • How to find all image tags of a running Docker container?
  • Filtering files with the given range of inputin perl
  • Save cat command output to file
  • escaping complicated command line arguments in bash and ssh
  • Socket incoming connections can not push_back elements concurrently to a globally defined std::vector
  • curl is downloading the html rather than the actual zip file from gitlab
  • shell scripting "test " command
  • No module named 'tensorflow.python.platform'
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk