How to break loop in callback functuion

I use PtOnOffButton widget and call my callbackfunction when I click OnOffButton.
My callbackfunction have loop for example

int
mycallbackfunction( …)
{

If ( STAE_ONOFFBUTTON  ==  on)

{

   while ( l < 2000)
  {
     .......... Myprocess( );
  }

}

If ( STAE_ONOFFBUTOON == off)
{
stop Myprocess();
}
Return(Pt_CONTINUE);
}

My Problem when i CLICK OnOff button to ON .Before My process is finished. I can not CLICK botton again . I would like to stop My Process during loop runing . How to slove it

Don’t loop forever inside of a Photon callback? Either start a thread or use a WorkProc. You can read about both options in the Photon helpviewer book on performing long running calculations.