Cannot display canvas while waiting for user input

Hi ROOT Experts,

While writing a simple ROOT macro, I’ve noticed that I’m unable to display a canvas while I’m waiting for user input to a cin. A simple example is below (Save as Example.C and run as “root.exe Example.C”).

You’ll see that I am making a simple plot. When my macro pauses to get user input to a cin however, the canvas is unable to display.

Are there any ideas to work around this?

Thanks in advance,
Will

Example(){

TH1F *h1 = new TH1F(“h1”, “h1 title”, 4, 0, 4);
h1->Fill(2);
h1->Draw();

bool WhileBool = 1;
while(WhileBool){

  cout<<"Enter 0 to exit the macro. Enter 0 to stay in while loop: "<<endl;
  cin>>WhileBool;

}

}

After “Draw” add “gPad->Modified(); gPad->Update();”,
You may also add “gSystem->ProcessEvents();” in your “infinite loop”.
(Note that “cin>>WhileBool;” will make the canvas not-responding to any mouse actions.)

Thanks once again Wile E Coyote! Your solution works great!