TApplication->Run method does not return

Dear all,
I am trying to use a TApplication instance to have some on-screen plots after my C program has analyzed data (the goal is to do a simple online monitor, where each time a binary file shows up in a directory it is opened, rootuplized and then some plots are shown on screen before the next file is produced). The problem is, when I use the ->Run() method, the histograms (which I drew before with the .Draw command) are correctly shown, but then the method does not return, and I have to press ctrl+c to end the program. I found on the web a simple TApplication example:

#include “TH1F.h”
#include “TApplication.h”
#include “TRint.h”

int main(int argc, char *argv[])
{
TApplication *myapp=new TApplication(“myapp”,0,0);
TH1F *h=new TH1F(“h”,“Test”,100,-10,10);
h->FillRandom(“gaus”,100000);
h->Draw();
myapp->Run();
return 0;
}

to be compiled as:

g++ namefile.c -I$ROOTSYS/include root-config --libs root-config --glibs -o exec

which I did, and it shows exactly the same problem as in my code (the plot is shown, but the program gets stuck just after and does not get to “return 0”)
Any hint?
Thanks
Regards

You can exit your application when, in any of the displayed canvases, you try its “main menu” item: “File” -> “Quit ROOT”.
If you do not want to wait for anything, simply don’t call “myapp->Run();” at all (you can call “gPad->Modified(); gPad->Update();” after you execute “Something->Draw();” in order to make sure that it’s really physically drawn on the screen.)

Thanks for the answer, but this is not what I need. Since this should be an online monitor, I would like ->Run() (or whatever it may be suited) to visualise the plots I draw every time a data file is found by the program. So the TCanvas should stay on screen, but the program should continue working, and update the histograms on the screen as soon as a new data file is processed. Of course nothing like manually exiting the application should be foreseen, as these are plots updated about every 60 seconds and displayed on a control screen during the acquisition, so that people can check that everything is ok.
If TApplication->Run is not the right way to proceed, do you know what should I use?
Thanks

If you manage the “infinite loop” yourself, don’t call “TApplication::Run” at all.
Inside of your “infinite loop” you may call “gSystem->ProcessEvents();” in regular intervals.