Solved

VB threading or an alternative question

Posted on 2013-07-01
8
183 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 45

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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 44

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 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now