how can i Run-once code from web service without calling the function from on_start?

Posted on 2009-06-26
Last Modified: 2012-05-07
Here i am calling the SendMails() event from onstart event. while i am adding this one to web service taking more time to start the webservice.

now i want to call the sendmail event only once after the web service started.

or is any other method to send the mails other than using webservice.
Imports System.ServiceProcess

Imports System.Data.SqlClient

Imports System.Web.Mail

Public Class service1

    Inherits System.ServiceProcess.ServiceBase


	Dim sql As String

    Dim MyCon As SqlConnection

    Dim MyCmd As SqlCommand

    Dim MyRd As SqlDataReader

    Public conStr As String = "connection string"

    Protected Overrides Sub OnStart(ByVal args() As String)


    End Sub

    Protected Overrides Sub OnStop()

    End Sub

    Public Function SendMails()

        Dim sno As Int64

        Dim strMailBdy As String

        Dim msgMail As MailMessage

        Dim strAryEmail(5000) As String


            sql = "select Email from TUser where Sno between 1 and 50000"

            MyCon = New SqlConnection(conStr)


            MyCmd = New SqlCommand(sql, MyCon)

            MyRd = MyCmd.ExecuteReader

            sno = 0

            While MyRd.Read

                strAryEmail(sno) = MyRd("Email")

                sno = sno + 1

                If sno > 4999 Then

                    ReDim Preserve strAryEmail(sno + 1)

                End If

            End While


            MyCmd = Nothing


            Dim intCustLen As Int64

            intCustLen = sno - 1

            For sno = 0 To intCustLen Step 1

                If strAryEmail(sno).ToString <> "" Then


                    msgMail = New MailMessage

                    msgMail.To = strAryEmail(sno).ToString.Trim

                    msgMail.From = "From EmailID"

                    msgMail.Subject = "Subject"

                    msgMail.Body = "Email Body"

                    msgMail.BodyFormat = MailFormat.Html

                    msgMail.Priority = MailPriority.Normal




                    Catch ex As Exception

                    End Try


                End If


        Catch ex As Exception

            If MyCon.State = ConnectionState.Open Then MyCon.Close()

        End Try

    End Function

End Class

Open in new window

Question by:Ranjith_MCAD
1 Comment
LVL 11

Accepted Solution

Salim Fayad earned 500 total points
ID: 24727251
You can send emails from your web application directly without passing thrugh a webservice. But if you do want to do it from your webservice, you can write a function in your webserice that you call it from your web application.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

12 Experts available now in Live!

Get 1:1 Help Now