Solved

VB threading or an alternative question

Posted on 2013-07-01
8
192 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…

821 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