|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie: multithreading (?)Hi,
I am not sure if multithreading is the answer but i wonder what should i do and how to prevent the "locking" of a form and event response when there is some activity that takes too much time. For example, i open a data file and process the data. While processing, the form looks as if it hangs. How come "professional" applications dont do that? Just showing the hourglass is not enough. What should i do to allow other user interaction and process the data in the "background". Thanx in advance! -Steve
Show quote
Hide quote
On Sat, 22 Oct 2005 02:50:08 -0400, "smith" <jsm***@yahoo.ca> wrote: Put a load of DoEvents in the bit that is doing the processing>Hi, > >I am not sure if multithreading is the answer but i wonder what should i do >and how to prevent the "locking" of a form and event response when there is >some activity that takes too much time. > >For example, i open a data file and process the data. While processing, the >form looks as if it hangs. >How come "professional" applications dont do that? Just showing the >hourglass is not enough. > >What should i do to allow other user interaction and process the data in the >"background". Be careful to prevent the system 're-entering' the same routine
Show quote
Hide quote
"J French" <erew***@nowhere.uk> wrote While Doevents would be the right answer, I would rather suggest that> >I am not sure if multithreading is the answer but i wonder what should i do > >and how to prevent the "locking" of a form and event response when there is > >some activity that takes too much time. > > > >For example, i open a data file and process the data. While processing, the > >form looks as if it hangs. > >How come "professional" applications dont do that? Just showing the > >hourglass is not enough. > > > >What should i do to allow other user interaction and process the data in the > >"background". > > Put a load of DoEvents in the bit that is doing the processing > > Be careful to prevent the system 're-entering' the same routine it be used very sparingly, instead of dropping in a 'load'. ;-) If there is a loop executing one iteration every 5 ms that takes 3 minutes to complete, then simply ading one DoEvents inside the loop could bump that up to a 7 minute event. DoEvents only needs to execute 4 or 5 times a second for it to allow normal user activity. To do that, some sort of counter (or the loop iterator) could be used to be sure DoEvents only gets called once in a while: For idx = 0 to 999999 ' Other code If (idx And &HFFF) = &HFFF then DoEvents Next In that way DoEvents is only called once for every 4096th iteration. The values would need to be adjusted, depending on how much time that other loop code requires, so that DoEvents is called only a few times in a second, rather than on every iteration. The 'watch out for re-entry' conditions still remain.... LFS On Sat, 22 Oct 2005 06:03:31 -0500, "Larry Serflaten"
<serfla***@usinternet.com> wrote: Show quoteHide quote > Yes, agreed>"J French" <erew***@nowhere.uk> wrote >> >I am not sure if multithreading is the answer but i wonder what should i do >> >and how to prevent the "locking" of a form and event response when there is >> >some activity that takes too much time. >> > >> >For example, i open a data file and process the data. While processing, the >> >form looks as if it hangs. >> >How come "professional" applications dont do that? Just showing the >> >hourglass is not enough. >> >What should i do to allow other user interaction and process the data in the >> >"background". >> Put a load of DoEvents in the bit that is doing the processing >> Be careful to prevent the system 're-entering' the same routine >While Doevents would be the right answer, I would rather suggest that >it be used very sparingly, instead of dropping in a 'load'. ;-) - what I should have said is shove in a load of DoEvents until things look Ok, then start removing them until things deteriorate. I kind of forgot to mention the Golden Rule - remove redundancies Astutely caught |
|||||||||||||||||||||||