Generally speaking you should not run blocking code (like a long running while-loop) in the main thread because it makes the app unresponsive -- all functions should preferably return in milliseconds. In your case you also expect the main loop to call your other event handler but never give the main loop a chance to do it: the while loop just keeps executing forever. In other words: the first handler needs to return before the main loop can call the second one.
How to fix that depends on what your actual problem is: Using asynchronous code or idle handlers should be the first option, and a worker thread is another (but please only add threads when you know that you actually need them). It's also possible to "pump" the event loop manually but that should really be the last option. See main loop reference for details.
Your example would look something like this:
gboolean check_connection (gpointer user_data)
{
/* g_print what you want based on check value */
if (check == 0)
return FALSE;
return TRUE;
}
void button1_clicked_do_job(GtkWidget *widget, gpointer data1)
{
g_timeout_add_seconds (2, check_connection, NULL);
}