App doesn't quit



I've written the following test app:

/* gtktest.c */
#include <pthread.h>
#include <gtk/gtk.h>

static pthread_t thr;

void *BgTask(void *p)
{
    printf("Background task started\n");
    sleep(10);
    gtk_main_quit();
    printf("Background task stopped\n");
    pthread_exit(p);
}

int CreateBgTask(void)
{
    if (pthread_create(&thr, NULL, BgTask, NULL) != 0) {
        printf("Cannot create background task\n");
        return -1;
    }
    return 0;
}

gint deleteCb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
    gtk_main_quit();
    return FALSE;
}

gint destroyCb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
    gtk_main_quit();
    return 0;
}

int main(int argc, char *argv[])
{
    GtkWidget *win;

    gtk_init(&argc, &argv);

    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_signal_connect(GTK_OBJECT(win), "delete_event", GTK_SIGNAL_FUNC(deleteCb), NULL);
    gtk_signal_connect(GTK_OBJECT(win), "destroy", GTK_SIGNAL_FUNC(destroyCb), NULL);
    gtk_widget_show(win);

    CreateBgTask();

    gtk_main();

    return 0;
}
/* end of file */

I executed the app and expected the app to be terminated after around 10 seconds.  But it did not.

However, when I pressed a key or moved the cursor over the app window, the app was terminated normally.

It seems like that the call to gtk_main_quit() in BgTask() cannot quit the app until there is event sent to 
the app.

Can anyone tell me why?

Is there any way to quit the app without pressing the 'exit' button of the app window?

Regards,
Au Chi Wa
ERG HK



---------------------------- ERG Group --------------------------
 The contents of this email and any attachments are confidential
 and may only be read by the intended recipient.
-----------------------------------------------------------------





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]