Solved

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

Posted on 2009-05-08
13
247 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 74

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 74

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 74

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

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

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 74

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 74

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

24 Experts available now in Live!

Get 1:1 Help Now