Link to home
Start Free TrialLog in
Avatar of Derrick Hammond
Derrick HammondFlag for United States of America

asked on

VB threading or an alternative question

I am currently developing a solution in VB that needs to be able to send a set of emails in the background. I have been able to spin off a new thread to send the emails in the background, which works just fine, but a very serious question has arisen.

"What if the user logs out and closes the application? Will this in-turn close the thread that is sending the emails?"

There is a potential for this background process to be sending out hundreds of emails which could take a significant amount of time ( say 10 minutes or so). One of the instances of this will happen at the end of the users work day and would potentially happen just before the user logs out at the end of the day.

So, to the ultimate question of this post:
Is threading the answer for sending background emails or should I be looking into a different solution?
Avatar of aikimark
aikimark
Flag of United States of America image

are you writing this in VB6 or VB.Net?
Avatar of Derrick Hammond

ASKER

This application is written in vb6.
Avatar of HooKooDooKu
HooKooDooKu

Sounds like you just need a way to communicate to the 2nd Process.

VB wasn't designed for multi-threading processes, so it takes some creativity on how to effectively communicate.  While I'm sure there are elegant ways to communicate using COM objects and stuff like that, a down and dirty simple example can be to simply communicate through a file.  As an example, you could create a TEMP file in the main process and pass that file name to the 2nd process when you kick it off.  As the 2nd process executes, it can periodically read the contents of this TEMP file to decide what to do.  As an example, if a person logs off the 1st process, the log-off process could update this file to simply contain the text "STOP".  When the 2nd process next checks the content of the TEMP file, it finds "STOP" and aborts the process.

Of course you might have to get a bit more creative if you want to handle situations such as what if the 1st system crashes (in which case, you could start doing things like having the 1st process periodically update the contents of the TEMP file... and the 2nd process only continues to process when it sees the contents of the file change).  You could even have two TEMP files so that the two processes can communicate both ways.
My apologies experts.

I miss typed my last reply as to my project being in vb6. I read the question as I was typing and typed in vb6 and sent the comment without rereading my reply.

The project is written in vb.net targeting .net 3.5.

Sorry guys and gals!
>>>What if the user logs out and closes the application? Will this in-turn close the thread that is sending the emails?

Yes - IF the application is closed.  There isn't an easy solution to stopping the user aborting your job.

Simplest  - display a message requesting not to close, close the app yourself when complete
Complex - keep track of what has been sent and at next startup continue where left off.
Andy -
How does the thread respond when the isBackground property of the thread is set to false?
Does closing the application kill the process?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial