how to do this in windows service
-
i have this code and i want this as a windows service. i like this to execute every 20 secs Dim olapp As New Outlook.Application Dim olNs As Outlook.NameSpace Dim myrecipient, myfolder Dim myitems As Outlook.Items Dim mymail As Outlook.MailItem Dim myitem As Object Dim myConnection As SqlConnection Dim myCommand As SqlDataAdapter Dim cmd As New SqlCommand olapp = CreateObject("Outlook.application") olNs = olapp.GetNamespace("MAPI") myrecipient = olNs.CreateRecipient("someusername") myrecipient.resolve() If myrecipient.resolved Then myfolder = olNs.GetSharedDefaultFolder(myrecipient, Outlook.OlDefaultFolders.olFolderInbox).Items End If myitems = myfolder myConnection = New SqlConnection("Data Source=.....") myCommand = New SqlDataAdapter myitems = myitems.Restrict("[Unread] = true") myConnection.Open() For Each myitem In myitems On Error Resume Next cmd = New SqlCommand("Insert into NewMessages (EntryID,SenderName,Subject,ReceivedTime,Body,UnRead) values(@EntryID ,@SenderName,@Subject,@ReceivedTime,@Body,@UnRead)", myConnection) cmd.Parameters.Add(New SqlParameter("@EntryID", SqlDbType.Variant)) cmd.Parameters("@EntryID").Value = myitem.entryid cmd.Parameters.Add(New SqlParameter("@SenderName", SqlDbType.NVarChar, 100)) cmd.Parameters("@SenderName").Value = myitem.sendername cmd.Parameters.Add(New SqlParameter("@Subject", SqlDbType.NVarChar, 1000)) cmd.Parameters("@Subject").Value = myitem.subject cmd.Parameters.Add(New SqlParameter("@ReceivedTime", SqlDbType.DateTime)) cmd.Parameters("@ReceivedTime").Value = myitem.ReceivedTime cmd.Parameters.Add(New SqlParameter("@Body", SqlDbType.Variant))cmd.Parameters("@Body").Value = myitem.Body cmd.Parameters.Add(New SqlParameter("@UnRead", SqlDbType.NChar, 5))cmd.Parameters("@UnRead").Value = myitem.UnRead cmd.ExecuteNonQuery() Next myitem myConnection.Close() olapp = Nothing olNs = Nothing myrecipient = Nothing myfolder = Nothing myitem = Nothing myitems = Nothing myrecipient = Nothing i've already created a service for this one but, on its first start, it extracts unread mails, but when new mails come, it does not extract anything and when i checked on the application log it says, Microsoft Office 11 - Rejected safe mode action - Microsoft Outlook. on the system log: DCOM - The server {0006F03A-0000-0000-C000-000000000046} did not register with DCOM within the required timeout. I already uninstalled and killed the service but i'm still getting this errors on the eventlog. why is this so? i think i