# Wx::Timer

**URL:** <https://www.ruby-forum.com/t/wx-timer/165292>\
**Category:** wxRuby\
**Created:** [April 11, 2009, 4:39pm UTC](https://www.ruby-forum.com/t/wx-timer/165292 "2009-04-11T16:39:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [April 11, 2009, 4:39pm UTC](https://www.ruby-forum.com/t/wx-timer/165292/1 "2009-04-11T16:39:18Z")

</div>

I want to process and event at regular time intervals. It appears that  
Wx::Timer should do the job, but I haven’t been able to figure out how  
to use in in wxruby. The documentation for this is still for C++. I’ve  
tried the following:

(In my form class’s initialize method):  
@timer = Wx::Timer.new  
evt\_timer(@timer.id) {|event| onTimer(event)}  
@timer.start(1000)

Later in the form, I have the onTimer routine defined. The problem is  
that its never being called.

Does anyone know how to use Wx::Timer?

Thanks in advance  
—Michael

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [April 11, 2009, 6:40pm UTC](https://www.ruby-forum.com/t/wx-timer/165292/2 "2009-04-11T18:40:19Z")

</div>

Hi Michael,

Try using the following:

```
@timer = Wx::Timer.new(self, -1)
evt_timer(@timer.id, :on_timer)

```

* * *

From: Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: removed\_email\_address@domain.invalid  
Sent: Saturday, April 11, 2009 9:39:18 AM  
Subject: [wxruby-users] Wx::Timer

I want to process and event at regular time intervals. It appears that  
Wx::Timer should do the job, but I haven’t been able to figure out how  
to use in in wxruby. The documentation for this is still for C++. I’ve  
tried the following:

(In my form class’s initialize method):  
@timer = Wx::Timer.new  
evt\_timer(@timer.id) {|event| onTimer(event)}  
@timer.start(1000)

Later in the form, I have the onTimer routine defined. The problem is  
that its never being called.

Does anyone know how to use Wx::Timer?

Thanks in advance  
—Michael

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [April 14, 2009, 2:33pm UTC](https://www.ruby-forum.com/t/wx-timer/165292/3 "2009-04-14T14:33:55Z")

</div>

Michael S. wrote:

> I want to process and event at regular time intervals. It appears that  
> Wx::Timer should do the job, but I haven’t been able to figure out how  
> to use in in wxruby. The documentation for this is still for C++.

The introductory documentation here:  
[http://wxruby.rubyforge.org/doc/timer.html](http://wxruby.rubyforge.org/doc/timer.html) is correct for Ruby (though  
it seems to have a few formatting errors). For what you want the best  
way would be as the first example on that page:

Wx::Timer.every(500) do  
puts “Tick”  
end

hth  
alex
