cancel
Showing results for 
Search instead for 
Did you mean: 

Multithreading Question

Former Member
0 Kudos

Using Eric Aling's example http://eric.aling.tripod.com/PB/tips/pbtip25.htm for multi-threading, I can't seem to find a way to have a process running in the main application's thread NOT stop the multi-threaded processes.

For example, if I place a multi-line edit control on the main w_multithread window, after clicking the MultiThreaded command button, I am not able to enter any text in the mle until after both threads have finished. However, if I put in yields as follows in the nv_test nvo, then I can easily enter text into the mle while the 2 threads are doing their work:

time t1

t1 = now()

do while secondsafter(t1,now()) < 20

  il_Count++

  yield()

  inv_arg.triggerevent('ue_thread')

  yield()

loop

return 1

However, what I don't understand is if I put a new command button on the main w_multithread window that runs a loop for 20,000 iterations and sets the value of a static text control to the String of the count, then after clicking the MultiThreaded command button, this loop will stop the 2 threads from doing their work until this loop has finished. Why is that if this loop is in the main application thread and the other 2 threads are not?

Even if I open a new window to perform the counting in the main thread, it too will stop the other 2 threads.

Any help is appreciated.

Kind Regards,

Greg

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Gregory;

  I wonder if it's the way that particular example was coded? I have a multithreading example that might work better. You can download it here.

Regards ... Chris

Former Member
0 Kudos

Hi Chris,

Looks like you were onto something here. Using your example (and thank you for that), when I place a commandbutton and a static text on wn_mt_thread_e with the following code:

Long ll_count

FOR ll_count = 1 TO 80000

  st_count.TEXT = String(ll_count)

  yield()

NEXT

then start the thread, then start this counting loop, it does in fact NOT stop the thread processing. It definitely needs the yield in there though.

Anyway, again thanks. The reason I'm doing this is to run Mobilink Synchronization asychronously from our application and I wanted to make sure the main application thread would not stop any of the ML processing.

Again, thanks.

Kind Regards,

Greg

Former Member
0 Kudos

Excellent news!

Yes, you always need a yield () when running in a tight loop. Otherwise, the other threads will not be dispatched. Its the old saying "being a good corporate citizen" - everyone respecting each others common environment in a symbiotic relationship.   😉

Former Member
0 Kudos

BTW, I like the way your framework "encourages" you to use all controls inherited from your base class. When I put the static text control on there the warning pops up - not sure I saw one for the commandbutton, but anyway, thanks for your help.

Kind Regards,

Greg

Former Member
0 Kudos

Thanks!

Yes, a neat little system-to-system check for all classes that they come inherited from the Framework. I saw too many PFC people shoot themselves in the foot by not following this rule and have their PFC applications die horribly at runtime or misbehave. So I wanted to make sure that my framework always validated its surroundings. All visual classes will let you know with a message box. All non-visual classes will terminate with a message to the Application log.

The Web Service framework also does these system-to-system checks as well.    😉

Answers (1)

Answers (1)

former_member190719
Active Contributor
0 Kudos

Are you sure you're running that sample in multithreaded mode?  It has two modes, one single threaded and one multithreaded so you can see the difference.

Former Member
0 Kudos

Definitely running the multi-threaded mode. I'll give Chris' a look at and see if the same behavior exists or if it's something I'm missing.

Thanks for the quick responses.

Greg