Text Window freez and expect for some mouse event

I have created a program to display text in text field in X window.

I have created a loop to display name of various elements.

For 1st element
XtSetValue()displays the text in text window. so after that

XtAppPending(appCon)
XtAppNextEvent (appCon, &ev);
XtDispatchEvent (&ev);

Work smoothly. It does not expect any event.

But for 2nd and more elements

XtSetValue() does not display text in text window.

Text is visible only after hitting the
XtAppPending(appCon) function

but after that

XtAppNextEvent (appCon, &ev);

function expects some mouse event.

Where as I want Window should disappear after some time, until unless user does not do any action say press cancel or help button.

I have used XtAppAddTimeOut function also.

void tlaguiWorkDialogText_c::EventLoop1()
{
static int timing_out = 0; /* Don't reenter! */
XtIntervalId timeout;

if (XtAppPending(appCon) && !timing_out)
{
XEvent ev;
timing_out = 1;
timeout = XtAppAddTimeOut (appCon, (unsigned long)2000,(XtTimerCallbackProc)tlaguiWorkDialogText_c:EventLoop1,(XtPointer) NULL);

do {
XtAppNextEvent (appCon, &ev);
XtDispatchEvent (&ev);
} while (ev.type != KeyPress && ev.type != KeyRelease && ev.type != ButtonPress && ev.type != ButtonRelease);

XtRemoveTimeOut(timeout);
timing_out = 0;
}
}

But still i am facing same problem.

Please suggest me, How can I resolve this issue.

Thanks & Regards
Vivek Garg
vivek.garg@wipro.com