Solved

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

Posted on 2009-05-08
13
261 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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