Solved

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

Posted on 2009-05-08
13
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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 article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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