#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>
#include <WSDthread.h>
#include <stdlib.h>
#include <unistd.h>
//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
#include <newwin000.h>
WSDthread* thr = NULL;

//running as the sub thread.
void* thread_func(WSDthread* obj,void* ptr){
  long cnt= (long)ptr;
  while(1){
    cnt++;
    obj->execCallback((void*)cnt);
#ifdef MSW
    Sleep(1000);
#else
    sleep(1);
#endif
  }
  return NULL;
}

//running on the main thread.
void callback_func(WSDthread*,void* val){
  long cnt = (long)val;
  //display the counter
  newvbtn_000->setProperty(WSNlabelString,cnt);  
}

//running on the main thread.
void btnop(WSCbase* object){
  //create a thread to count it up.
  if (thr == NULL){
    thr = WSDthread::getNewInstance();
    thr->setFunction(thread_func);
    thr->setCallbackFunction(callback_func);
    thr->createThread((void*)100);
  }else{
    exit(0);
  }
}
static WSCfunctionRegister  op("btnop",(void*)btnop);
