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 ......