Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB threading or an alternative question

Posted on 2013-07-01
8
Medium Priority
?
202 Views
Last Modified: 2013-07-24
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?
0
Comment
Question by:Derrick Hammond
8 Comments
 
LVL 46

Expert Comment

by:aikimark
ID: 39293134
are you writing this in VB6 or VB.Net?
0
 

Author Comment

by:Derrick Hammond
ID: 39293326
This application is written in vb6.
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 39297214
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Derrick Hammond
ID: 39302289
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!
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 39302673
>>>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.
0
 

Author Comment

by:Derrick Hammond
ID: 39311807
Andy -
How does the thread respond when the isBackground property of the thread is set to false?
Does closing the application kill the process?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 39314623
There is another option. Create a service for sending the emails out and use the application to just queue the work for service. User logging off or closing application will not affect this service.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question