Languages

Menu
Sites
Language
EventDrivenThread: sending/receiving events problem

Hi There,

I want to run a long processing job in a thread. During this, I show the progress of this job on the GUI Form. Every time the thread finishes 1% of the job, it sends an event to the Form, which steps a progressbar in the OnUserEventReceivedN.

I found the following problem / bug:
If you create an EventDrivenThread, and inside it's OnUserEventReceivedN() you are sending event to the main thread, those events are not delegated to the main thread until you touch the screen(!), or wait quite some time, then they are delivered in one goal, then again nothing, then again many.
My experiences are based on the emulator.

Thread:

void MyThread::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
{
    for (int j = 0; j < 100; ++j)
    {
        AppLog("Sending EVENT_1...");
        _ownerForm->SendUserEvent(0, 0);
        Thread::Sleep(3000);
    }
}

MainForm:

 

void testThreadForm::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
{
    AppLog("requestId=%d", requestId);
}

Output:

0:00 Sending EVENT_1...
0:00 requestId=0
0:03 Sending EVENT_1...
0:06 Sending EVENT_1...
0:09 Sending EVENT_1...
0:09 requestId=0
0:09 requestId=0
0:09 requestId=0
0:12 Sending EVENT_1...
0:15 Sending EVENT_1...
0:18 Sending EVENT_1...
0:21 Sending EVENT_1...
0:24 Sending EVENT_1...
0:27 Sending EVENT_1...
0:30 Sending EVENT_1...
0:33 Sending EVENT_1...
0:36 Sending EVENT_1...
0:39 Sending EVENT_1...
0:39 requestId=0
0:39 requestId=0
0:39 requestId=0
0:39 requestId=0
0:39 requestId=0
0:39 requestId=0
0:39 requestId=0
0:39 requestId=0
0:39 requestId=0

While it should be:

0:00 Sending EVENT_1...
0:00 requestId=0
0:03 Sending EVENT_1...
0:03 requestId=0
0:06 Sending EVENT_1...
0:06 requestId=0
...

 

If I start touching the screen, I got the correct order/callback.
Sample App: https://docs.google.com/file/d/0B6SsFyPBmm_CODloWGJ4YmI5MkE

*********** UPDATE ************

I tried with worker threads too, and the same problem:

Object* MyThreadWorker::Run(void)
{
    for (int j = 0; j < 100 && !_stop; ++j)
    {
        AppLog("Sending EVENT_1...");
        _ownerForm->SendUserEvent(999, 0);
        Thread::Sleep(3000);
    }
    return null;
}

Output

0:00 Sending EVENT_1...
0:00 requestId=999
0:03 Sending EVENT_1...
0:06 Sending EVENT_1...
0:09 Sending EVENT_1...
0:12 Sending EVENT_1...
0:15 Sending EVENT_1...
0:15 requestId=999
0:15 requestId=999
0:15 requestId=999
0:15 requestId=999
0:15 requestId=999

And also, if I "touching" the screen randomly, the events are dispatched normally. Probably a screen thouch forces events to be processed?

*********** UPDATE 2 ************

I found a "workaround": if I send an event to the Application too in the thread, then it works fine. Strange. I think this is a bug.

Object* MyThreadWorker::Run(void)
{
    for (int j = 0; j < 100 && !_stop; ++j)
    {
        AppLog("Sending EVENT_1...");
        _ownerForm->SendUserEvent(999, 0);
        _ownerApp->SendUserEvent(55555, 0);   //workaround, sending a dummy event
        Thread::Sleep(3000);
    }
    return null;
}

Output

0:00 Sending EVENT_1...
0:00 requestId=999
0:03 Sending EVENT_1...
0:03 requestId=999
0:06 Sending EVENT_1...
0:06 requestId=999
......

 

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

6 Replies
youngsik yoon
i'm not sure, if this is bug or not. i found following comments about SendUserEvent from dev guide. https://developer.tizen.org/help/index.jsp?topic=%2Forg.tizen.native.appprogramming%2Fhtml%2Fguide%2Fui%2Fevent_handling.htm "A simple example of a custom event is to send an event from an event handler to the main form. Another example is that of inter-thread communication. In this case, UI handling is done in the main application thread. If the application spawns a thread, calling the SendUserEvent() method in that thread causes a thread context change. The Tizen::App::App::OnUserEventReceivedN() event handler is called in the main application context."
Kamil N

I observed similar issue on the device running tizen 2.2. I do some operations on many photos in the separate thread than UI and sending update to the Form using SendUserEvent. I tried many aproaches but still I cannot solve this issue:

Example code:

1)

for (i=0;i<length;i++) {

//do some action

form->SendUserEvent(INCREASE,null);

}

form->SendUserEvent(DONE,null);

on the begining everything is fine but after some time (usally on the half of the length) user events are not send until I touch the screen, then everything is ok but I need to touch screen to force send event.

************************

Code 2)

for (i=0;i<length;i++) {

//do some action

form->IncreaseProgress(level); //calls progress->setLevel(level);

}

form->SendUserEvent(DONE,null);

on the begining progress correctly shows value but after some time it stops until I touch the screen. (I tried Redraw form and progress)
****************************8
 
Example code 3)

for (i=0;i<length;i++) {

//do some long action

}

form->SendUserEvent(DONE,null);

Even now event is not send until I touch the screen. Is this a bug? 

 

Thanks for your help! 

Kamil N

Update:

When I remove function which is working for some time it works fine. I tried to replace this function with Sleep but effect is the same. Events are comming after I touch the screen

Zoltan Puski

I found a workaround, just read my note above

Kamil N

I saw and I used your workaround. Now works fine thanks! However I wanted to describe my problem, it might be a bug

 

 

Zoltan Puski

Yes, we have / had the same problem.
I also think this is a bug. If not, it should be clearly documented somwehere