这个方法是在基于用进程不行,线程又有问题的基础上,而实现的一种可以实现定时执行某个功能的方法。
比如每过300ms 更新个标签等。
static gint
gtk_clock_timer (GtkWidget* button)
{
gchar time[22];
// if have destroyed all the button then stop the timer
if(0 == clock_count)
{
return TRUE;
}
get_host_time(time);
gtk_button_set_label((GtkButton *)button, time);
gtk_timeout_add (CLOCK_DELAY,
(GtkFunction) gtk_clock_timer,
(gpointer) button);
return FALSE;
}
static void time_init( GtkWidget** button_p)
{
GtkWidget *button = NULL;
button = gtk_button_new();
*button_p = button;
g_signal_connect (GTK_OBJECT (button), "clicked", G_CALLBACK (clicked_cb), NULL);
timer[clock_count] = gtk_timeout_add (CLOCK_DELAY,
(GtkFunction) gtk_clock_timer,
(gpointer) button);
gtk_widget_show_all(*button_p);
clock_count++;
return;
}