Process running thread - best option

Hello,

I try to have a CRM done with XOJO and one of the tasks is to fetch some data from an imap account on regular intervals and do some processing. What would be the best thing to do here ?

I was thinking to have a thread with a timer in App that will fire once app started and check the mail every 5 min and do the needed processing, is there a better way ?

Thanks

Timers execute the code in the Run event in the Main Thread, preventing the server to process browser events and connections while that code is being running. If you want to use a Timer with a Thread, you can Start the thread from the Timer.

If IMAPThread.ThreadState = Thread.ThreadStates.NotRunning Then
  IMAPThread.Start
End If

Another way, without having to use a Timer, would be to just have a Thread that runs forever in a loop, with a Sleep inside that sleeps the Thread after each loop.

As a third option, you can have a separate Console project in charge of connecting and processing the emails. It can communicate with your Web application using a shared database, for example.

Thanks Ricardo, i was looking for the second and third option as well but i just want to keep track of one project so i wanted to have all in one. In case the tasks that are added in the thread will become more complex then maybe i will shift those to a separate console app.

1 Like