0

我的应用程序中有一个显示信息的类。
我必须通过 SOAP 从服务器获取这些信息。
这是我的课:

class InfoControl : public TGCompositeFrame {
private:
    //char*, int....
    bool bWorking;
public:
    InfoControl(const TGWindow *p);
    virtual ~InfoControl();
    void SetEventRate(char* evnum);
    void SetBufferRate(char* rate);
    void SetSuccess(char *s);
    void RequestInfo();
    ClassDef(InfoControl,1)  //useless : ROOT specific stuff
};

RequestInfo()只要bWorking是真的,我希望定期调用方法。我对pthread解决方案感到满意,但不知道如何实施。也许更微不足道的事情是可能的?

提前感谢您的帮助,
eo。

4

3 回答 3

0

嗯... Mb

while (bWorking)
{
    RequestInfo();
    /* sleep os sleep function, or boost, or something else. 
    time - period to sleep.*/
    sleep(time);
}

或者你想要异步调用,有一些计时器?

于 2012-07-10T12:42:38.697 回答
0

有点不清楚RequestInfo()应该对外部产生什么样的影响,因为它是 a void,但如果它以某种方式与外部对话并且不专门做一些内部工作(然后在额外的线程中运行它就可以了)你应该也许重新考虑你的设计。

bWorking already is private, so an InfoControl knows when it changes. You could then use something like ROOT's Qt slots implementation (e.g. with a TQObject) to trigger a needed action only when bWorking changes (e.g. hook that into some SetWorking()).

于 2012-07-10T13:07:20.567 回答
0

Ok, found out. If someone has the same issue :

TTimer *timer = new TTimer();  
timer->Connect("Timeout()", "InfoControl", this, "RequestInfo()");  
timer->Start(1000, kFALSE);
于 2012-07-11T09:04:22.200 回答