Poller-ception

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Reaction score
13
A poller within a poller :eek:

So I want to create a windows service (or actually, have already) that polls SQL Server every 60 seconds to see if there are any new instances of pollers I need to create. So for each record (which has several columns that helps configure the poller/what it needs to poll), every 60 seconds it looks if there's a change in the recordset/any new ones came along.

If a new record comes along, it creates a new poller programmatically.

My question now is, is that poller on it's own thread? or is it running in serialized succession of the other pollers already created?
 
A poller within a poller :eek:

So I want to create a windows service (or actually, have already) that polls SQL Server every 60 seconds to see if there are any new instances of pollers I need to create. So for each record (which has several columns that helps configure the poller/what it needs to poll), every 60 seconds it looks if there's a change in the recordset/any new ones came along.

If a new record comes along, it creates a new poller programmatically.

My question now is, is that poller on it's own thread? or is it running in serialized succession of the other pollers already created?

It depends what type of thread you're spawning, typically it would be a child thread so it will be running in 'serialized succession' I used quotes there because that could be such a misleading sentence.

So basically if I understand correctly. For every new record since the last poll, you want to instantiate a new poll thread with parameters given in the SQL DB record item? What is this new instantiated poller going to be doing? polling?
 
It depends what type of thread you're spawning, typically it would be a child thread so it will be running in 'serialized succession' I used quotes there because that could be such a misleading sentence.

So basically if I understand correctly. For every new record since the last poll, you want to instantiate a new poll thread with parameters given in the SQL DB record item? What is this new instantiated poller going to be doing? polling?

It's going to execute a command every x seconds. Like, check if a file in a directory exists, or run a calculation and post that back to SQL every 30 seconds or whatever

I don't want to modify the poller service each time I want something else to poll, nor do I want to add several poller services running on their own.

So this poller service is the "master" and checks SQL Server which is the "controller". It will spawn a new poller if SQL Server says it should (I'm leaving out a huge part of the dynamic nature of this)

it would look like this sort of:

<master poller elapsed=60000>
<sql check loop>
<poller elapsed=3000 />
<poller elapsed=1000 />
etc
</sql_check>
</master_poller>
 
Why not just spawn multiple threads and just manage those Task.Factory.StartNew()?
 
Why not just spawn multiple threads and just manage those Task.Factory.StartNew()?

Something like this?

Code:
class poller
{
    public static void ThreadProc()
    {
        for (;;)
        {

            Thread.Sleep(0);
        }
    }
    Thread myThread;
    public poller(){
        myThread = new Thread(new ThreadStart(ThreadProc));
        myThread.Priority = ThreadPriority.BelowNormal;
        myThread.Start();
    }
};

class WindowsService : ServiceBase
{
    poller thisPoller;
    public WindowsService()
    {
        this.ServiceName = "My Windows Service";
        this.EventLog.Log = "Application";

        this.CanHandlePowerEvent = true;
        this.CanHandleSessionChangeEvent = true;
        this.CanPauseAndContinue = true;
        this.CanShutdown = true;
        this.CanStop = true;
    }
    protected override void OnStart(string[] args)
    {
        base.OnStart(args);
        thisPoller = new poller();
    }
    protected override void OnStop()
    {
        base.OnStop();
    }
}

I'm used to poller pollers, not threads, so hence why I'm a bit in the dark :)
 
Last edited:
var taskHolder = Task.Factory.StartNew(() =>
{
Thread.Sleep(timeToStartNextStep);
StartStep(nextStep);
}, TaskCreationOptions.LongRunning);
 
A poller within a poller :eek:

So I want to create a windows service (or actually, have already) that polls SQL Server every 60 seconds to see if there are any new instances of pollers I need to create. So for each record (which has several columns that helps configure the poller/what it needs to poll), every 60 seconds it looks if there's a change in the recordset/any new ones came along.

If a new record comes along, it creates a new poller programmatically.

My question now is, is that poller on it's own thread? or is it running in serialized succession of the other pollers already created?

You done killing b*tches?
 
If I use LongRunning, it would just run the function, finish it and sleep in "timeToStartNextStep" till I stop the windows service?
 
If I use LongRunning, it would just run the function, finish it and sleep in "timeToStartNextStep" till I stop the windows service?

Long running ensures that it runs on its own thread. And yes i just queue the tasks up in a new thread and sleep them until they need to fire.
 
Long running ensures that it runs on its own thread. And yes i just queue the tasks up in a new thread and sleep them until they need to fire.

Thanks, will mull it over, won't mind taking this into 4.5 since I'm writing it from scratch. Would give us a boost in our KPA's
 
Wait, I can just do a "Do While False" type thing and let it run into infinity, because if the service is stopped, so will the thread be after... correct?
 
Are their any cool changes to Reflection? I'm currently using this:

Code:
Dim oType As System.Type
        Dim oAssembly As System.Reflection.Assembly
        Dim oObject As System.Object

        oAssembly = Assembly.LoadFrom("ClassLibrary1.dll")
        oType = oAssembly.GetType("ClassLibrary1.Class1")
        oObject = Activator.CreateInstance(oType)

        Dim methodsInClass() As MethodInfo = oType.GetMethods()
        For Each minfo As MethodInfo In methodsInClass
            If minfo.Name.Contains("GetType") = False And minfo.Name.Contains("ToString") = False And minfo.Name.Contains("Equals") = False And minfo.Name.Contains("GetHashCode") = False Then                
                minfo.Invoke(oObject, Nothing)
            End If
        Next

It loads a dll dynamically and runs any public method. vb.net I know, converting yadayada. But was hoping to add this into the service so that I can make the poller pluggable
 
Are their any cool changes to Reflection? I'm currently using this:

Code:
Dim oType As System.Type
        Dim oAssembly As System.Reflection.Assembly
        Dim oObject As System.Object

        oAssembly = Assembly.LoadFrom("ClassLibrary1.dll")
        oType = oAssembly.GetType("ClassLibrary1.Class1")
        oObject = Activator.CreateInstance(oType)

        Dim methodsInClass() As MethodInfo = oType.GetMethods()
        For Each minfo As MethodInfo In methodsInClass
            If minfo.Name.Contains("GetType") = False And minfo.Name.Contains("ToString") = False And minfo.Name.Contains("Equals") = False And minfo.Name.Contains("GetHashCode") = False Then                
                minfo.Invoke(oObject, Nothing)
            End If
        Next

It loads a dll dynamically and runs any public method. vb.net I know, converting yadayada. But was hoping to add this into the service so that I can make the poller pluggable

We have our workflow service register references to dll on disk and we load it at runtime using the dynamic keyword.

dynamic step = Activator.CreateInstance(type, BindingFlags.Public | BindingFlags.Instance,
null, new object[] { job }, null);

That way we dont need to search for any sort of property, we ensure all our process steps have inherited from an interface so we know it will have the method. And it works lekker:P
 
We have our workflow service register references to dll on disk and we load it at runtime using the dynamic keyword.

dynamic step = Activator.CreateInstance(type, BindingFlags.Public | BindingFlags.Instance,
null, new object[] { job }, null);

That way we dont need to search for any sort of property, we ensure all our process steps have inherited from an interface so we know it will have the method. And it works lekker:P

Yea I was thinking that too, but I'd like it so that our less-er-thinking(?) devs can go ahead and write their own dll and just plonk it in without doing anything fancy
 
Wait, I can just do a "Do While False" type thing and let it run into infinity, because if the service is stopped, so will the thread be after... correct?

If the service is stopped all threads spawned by it will die as well yes:P... if that's what you where asking.
 
Top
Sign up to the MyBroadband newsletter
X