Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Anyone doing multithreading in VFP?
Message
 
To
23/05/2009 14:54:00
Mike Sue-Ping
Cambridge, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01401052
Message ID:
01401678
Views:
85
Sounds like you're off to a good start with it! You are correct, you do need to define as many worker thread objects as you will need to run simultaneously. In one commercial app I have, I have ten.

Here's a quick example where a form is responsible for sending an email and can use up to 2 threads to do it.

Form's Load()
*--Create the worker objects for sending threaded mail.
This.m_oWorker1=CREATEOBJECT('VFPMTAPP.Worker.1')
This.m_oWorker2=CREATEOBJECT('VFPMTAPP.Worker.1')

*--The worker threads will call ThisForm.OnMailSent when the work is done
This.m_oWorker1.SinkNotified(This,"OnMailSent")  
This.m_oWorker2.SinkNotified(This,"OnMailSent")  
Part of the form's send mail button click()
IF ! ThisForm.m_oWorker1.Running
  *--NOTE: this thread calls a Multi-threaded DLL created in fox. 
  *--Send the parameters via array.
  =ThisForm.m_oWorker1.Run("SendSocketMail.SendSocketMail","SendMail",@laMailParms)
ELSE
  *--Try using the 2nd thread. 
  IF ! ThisForm.m_oWorker2.Running
      =ThisForm.m_oWorker2.Run("SendSocketMail.SendSocketMail","SendMail",@laMailParms)
   ELSE
      =WriteToLog("*ERR* All worker threads were already running. Could not send mail.", .T.)
   ENDIF  
ENDIF 
Previous
Reply
Map
View

Click here to load this message in the networking platform