473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Load DataSet within new thread??

Hi,

I use the following code to load a dataset to be used to send out emails.
All this is executed as a new thread. The reason I implanted the
_currentPageNumber is to control the amount of emails sent to the SMTP
server in one load.

As I wrote in my post earlier tonight I'm very new to threading and the
following code works fine when not run in a separate thread.

Imports System
Imports System.net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Mail
Imports System.Threading

Public Class NewsletterMailer

Private Class SendWorker
Public NewsletterGUID As String
Public PageSize As Integer
Private _currentPageNumber As Integer
Private _totalRecords As Integer
Private SendMail As New EmailMessage
Private SMTP As New SMTP
Private _filedata As New FileData
Private _newsletterData As New NewsletterData

Public Sub Send()
Try
Dim NewsletterManagement As New NewsletterDB
Dim EmailGroupsManagement As New EmailGroupsDB
Dim CustomerManagement As New CustomerDB
Dim FilesManagement As New FilesDB
Dim MemberManagement As New MemberDB

_newsletterData =
NewsletterManagement.GetNewsletter(NewsletterGUID)
_currentPageNumber = 1

' ## Loop until all pages has been processed
While _currentPageNumber > 0

' Get emails
Dim dsMembers As DataSet =
MemberManagement.GetEmailsByGroup(_currentPageNumb er, PageSize)

_totalRecords = dsMembers.Tables(1).Rows(0)(0)
If _totalRecords > 0 Then

' Prepare bulk send
' Do stuff here...

Dim dr As DataRow
For Each dr In dsMembers.Tables(0).Rows
' Code to send personalized email
SMTP.Send(SendMail)
SendMail.Recipients.Clear()
Next

Dim _totalPages As Integer
_totalPages =
CInt(System.Math.Ceiling((_totalRecords \ PageSize) + 1))

' Wait for system to catch up
Thread.Sleep(3000)

' Get next page number or 0 to end
If _currentPageNumber >= _totalPages Then
_currentPageNumber = 0
Else
_currentPageNumber += 1
End If
Else
_currentPageNumber = 0
End If

End While ' ## End loop

Catch ex As ThreadAbortException
System.Diagnostics.Debug.WriteLine("thread aborted: " &
ex.Message)
Finally
System.Diagnostics.Debug.WriteLine("cleanup")
End Try

End Sub
End Class

Private mailerThread As System.Threading.Thread
Public NewsletterGUID As String

Public Sub Send()
Dim SW As New SendWorker
With SW
.NewsletterGUID = NewsletterGUID
.PageSize = 400
End With

mailerThread = New System.Threading.Thread(AddressOf SW.Send)
mailerThread.Name = "SendNewsletter"
mailerThread.Start()
End Sub

End Class

And here's the code to invoke it:

Dim NewsletterMailer As New NewsletterMailer
_newsletterData = NewsletterManagement.GetNewsletter(NewsletterGUID)
NewsletterMailer.NewsletterGUID = NewsletterGUID
NewsletterMailer.Send()
Thankful for any kind help
Regards,
Jonah
Nov 17 '05 #1
4 1501
It seems like I forgot to mention what the problem was :-)

When doing debug in VB .NET I couldn't access the DataSet loaded by the
SendWorker class, why?
Although it seems to work as planned when runing it on the server.

Any opinions on if this is a good way or a bad way of doing it?

Thanks
Jonah
Nov 17 '05 #2
Hi Jonah,

Couldn't access it in what way?
In the program, in a watch window, in immediate mode?
dsMembers is Nothing?
dsMembers can't be examined?

Regards,
Fergus

ps I'm off to bed now. ZZzzzs for several hours. :-)
Nov 17 '05 #3
Hi!

Sorry, I meant in the Output window during break. I couldn't access the
DataSet the function were loading. But when running the project on the
staging server it works perfect, so I guess nothing is wrong really... :-)

Jonah

"Fergus Cooney" <fi******@tesco.net> skrev i meddelandet
news:uP**************@TK2MSFTNGP12.phx.gbl...
Hi Jonah,

Couldn't access it in what way?
In the program, in a watch window, in immediate mode?
dsMembers is Nothing?
dsMembers can't be examined?

Regards,
Fergus

ps I'm off to bed now. ZZzzzs for several hours. :-)

Nov 17 '05 #4
Hi!

Sorry, I meant in the Output window during break. I couldn't access the
DataSet the function were loading. But when running the project on the
staging server it works perfect, so I guess nothing is wrong really... :-)

Jonah

"Fergus Cooney" <fi******@tesco.net> skrev i meddelandet
news:uP**************@TK2MSFTNGP12.phx.gbl...
Hi Jonah,

Couldn't access it in what way?
In the program, in a watch window, in immediate mode?
dsMembers is Nothing?
dsMembers can't be examined?

Regards,
Fergus

ps I'm off to bed now. ZZzzzs for several hours. :-)

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Shabam | last post by:
A web application of mine developed using C# + MS SQL runs fine normally. However when I stress test it with a load testing software (using about 60 simultaneous users) some instances start...
1
by: paul-esposito | last post by:
Okay, so I'm the DBA not a developer, but I need a sanity check. All the data access to the database is controlled by Stored Procedures, the procedures are really granular, basically every table...
3
by: James Morton | last post by:
I am writing a c# windows forms application. I read in an XML file to a dataset for read-only access (by the user and the application logic). This is not an MDI app but has LOTS of seperate...
3
by: Jonah Olsson | last post by:
Hi, I use the following code to load a dataset to be used to send out emails. All this is executed as a new thread. The reason I implanted the _currentPageNumber is to control the amount of...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
0
by: Bob Davies | last post by:
Hi I have a webservice that retrieves data from a database, this is then returned to the calling client application built in windows forms within a dataset, however upon attempting to create...
2
by: Nick Hustak | last post by:
Hi, I've been trying to work with the XSDs and ran into a few road blocks. 1. Stored procedures that uses temp tables, i.e. #TempTable. The wizard complains that #TempTable is an invalid...
0
by: Ponnu | last post by:
Hi, My page takes a while to load(about 2 mins) since it has to bind data from different databases and this is how I plan to do it Run the function in a new Thread which gets the data and...
9
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.