Solved

where to start to set up a background process vb.net

Posted on 2009-05-08
13
251 Views
Last Modified: 2013-11-26
I really just need someone to help me understand what is the best way to solve the following problem. Should I build it as a web service maybe - i just dont know.

Basically I would like to build something into my website that routinely checks the database and performs some processing dependent on what it finds. This process should run independently of  any user session and it will continue to poll the database while the website is active.

I could write it as a typical web form and run it manually but there must be a way to automate it. I just dont know what it is.
0
Comment
Question by:JOHNFROG
  • 7
  • 6
13 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24335995
Have you considered running a Windows Service (not web)?
0
 

Author Comment

by:JOHNFROG
ID: 24336488
I want to be able to write the solution up similar to an aspx page with vb code behind, can I write a such a page and then load the url  as a windows service? I doubt its that easy. where to look ?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24336538
Maybe I misunderstood the question. So do you want some processing to be done while a user has the page visible in their browser, or do you mean while your website exists (meaning not taken offline)?
0
 

Author Comment

by:JOHNFROG
ID: 24336759
while the website exists. I want to be able to basically set an aspx to run on the server at a specified interval. I am quite capable of writing the code behind but wondering how I would implement it.

Perhaps though I am able to do this using services - thats what I am trying to find out.
0
 

Author Comment

by:JOHNFROG
ID: 24336773
NOT while the user has the browser session open. behind the scenes stuff
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24336924
I'm not trying to be a pain here, but I was just thinking that if you wrote a Windows service to run on your web server, it could do the checking/updating to the database. It would run in the background of your server and you could set it up to process on a timer.

This site has a fairly simple demonstration of writing services
    http://www.codeproject.com/KB/system/WindowsService.aspx

My main point in suggesting a win service is because you said you want background processing and automation.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:JOHNFROG
ID: 24337147
will have to look at that more closely tomorrow. appreciate your assistance so far.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 24337161
An even more trimmed down example could be as below. You would change the startTime and interval times accordingly, and you would modify the DoUpdate() function to handle your database access. From what I have here, a text file (C:\out.txt) is appended with the system time every 10 seconds (as defined by the interval TimeSpan).
using System;

using System.ComponentModel;

using System.Data;

using System.ServiceProcess;
 

namespace MySiteUpdate

{

    public partial class Service1 : ServiceBase

    {

        private System.Threading.Timer updateTimer;

        private TimeSpan startTime;

        private TimeSpan interval;
 

        public Service1()

        {

            InitializeComponent();

            this.startTime = new TimeSpan(0);

            this.interval = new TimeSpan(0, 0, 10);            

        }
 

        protected override void OnStart(string[] args)

        {

            this.updateTimer = new System.Threading.Timer(DoUpdate, null, this.startTime, this.interval);

        }
 

        protected override void OnStop()

        {

            this.updateTimer.Dispose();

        }
 

        private void DoUpdate(object data)

        {

            using (System.IO.StreamWriter w = new System.IO.StreamWriter("C:\\out.txt", true))

            {

                w.WriteLine(DateTime.Now.ToString());

                w.Close();

            }

        }

    }

}

Open in new window

0
 

Author Comment

by:JOHNFROG
ID: 24342552
thanks for that. I would need to convert to VB to make sense of it. But you have given me somewhere to start. should be able to proceed from here
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24354638
Do you need help with the conversion? I am fluent in both languages :)
0
 

Author Comment

by:JOHNFROG
ID: 24355558
wow. going above the call of duty. heck if you dont mind then that'll be very welcomed. I was going to get around to it sooner or more likely later.

appreciate ur help.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24356946
It's no big deal :) I really enjoy helping people here.

As a tip, make sure to mention which language you're coding in--even if the question doesn't really seem language specific. I, and I'm sure other experts as well, will look for the language an asker references. If I can't find one, then I usually default to whichever language I'm comfortable with (C# in my case). Even if an expert primarily codes in one language, they usually either know how to read/write the other(s) or can figure out how to translate it.

See below for translation :)
Imports System.ServiceProcess
 

    Partial Class Service1

        Inherits ServiceBase
 

        Private updateTimer As System.Threading.Timer

        Private startTime As TimeSpan

        Private interval As TimeSpan
 

        Public Sub New()

            InitializeComponent()

            Me.startTime = New TimeSpan(0)

            Me.interval = New TimeSpan(0, 0, 10)

        End Sub
 

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

            Me.updateTimer = New System.Threading.Timer(AddressOf DoUpdate, Nothing, Me.startTime, Me.interval)

        End Sub
 

        Protected Overrides Sub OnStop()

            Me.updateTimer.Dispose()

        End Sub
 

        Private Sub DoUpdate()

            Using w As System.IO.StreamWriter = New System.IO.StreamWriter("C:\\out.txt", True)

                w.WriteLine(DateTime.Now.ToString())

                w.Close()

            End Using

        End Sub
 

    End Class

Open in new window

0
 

Author Comment

by:JOHNFROG
ID: 24359942
awesome. thanks for that. you really gone the extra mile.

Makes alot more sense to me now. I will see what I can do with that.

much appreciated.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

16 Experts available now in Live!

Get 1:1 Help Now