hi,
i have a class handler and a class health monitor. i have 2 instanses of the handler class as primary and secondary. in the start of the appliacation the primary and th secondary handler is set. what i want to do is once the primary is set up every one minute i need to send a msg to the health monitor updating the status.

how do i do it in C# asp.net

appreicate a reply

thanks

Member Avatar for LastMitch

@anisha.silva

i have 2 instanses of the handler class as primary and secondary. in the start of the appliacation the primary and th secondary handler is set. what i want to do is once the primary is set up every one minute i need to send a msg to the health monitor updating the status.

Read this and used the example:

http://msdn.microsoft.com/en-us/library/system.web.mail.mailmessage.aspx

I dont beleive that anisha.silva is asking about email messages. This seems to be related to MVC if I am not mistaken. unfortunately, I do not have experience in this area.

Diagram i have attached a picture
so what i am trying to implement is the arrow going from hander to health monitor and from health monitor to the proxy

i was not asking about email messaging,

LastMitch - the link you provided me is to monitor a web application, but i want to monitor just one class in my applicatin

how i ddin't make you'll confuse

Member Avatar for LastMitch

LastMitch - the link you provided me is to monitor a web application, but i want to monitor just one class in my applicatin

Nice diagram!

So you want to monitor One Class in the Application.

Have you try to create Alert by sending a message to the Admin?

Like for example, if there is some activity in that One Class and it will alert you by sending an message to the Admin to let you know that there is some activity in that One Class?

So it's kinda like monitor that One Class.

Is this something you are looking for?

well actually i want to monitor 3 classes in the diagram, Handler, Result Engine and the Query Engine,
If i implemnt it for one class it is the same concept for the others too.

alert? how do i do that

what i am tryin to figure out is, say the Hander class do some processing, and suddenly it fails and there is no one to do the processing.so there should be some mechanism to track it. so that is y i am trying to make it, so that when it fails the Health monitor knows that it didn't send a msg in after 1 min(as an ex i gave 1 min), so then the health monitor, tell the proxy to being the second instanse of the handler up, and to handle the processing.

is it clear?

Another thing to consider, simplistic but could be good enough is to have the classes place date and time in the database and have your health monitors check for the date and time. Again, very simple, but it could let you know the process is still running or not. I do that for an app I have running on a server and seems to work fine.

Member Avatar for LastMitch

well actually i want to monitor 3 classes in the diagram, Handler, Result Engine and the Query Engine,

Like what hometownnerd suggest place date and time in the database have the health monitors check for the date and time looks good in the long run.

Base on your code you want three and maybe in the future you need to add another code for the new one. By having a query it will keep the code in tact.

so want to make sure that i understood it.
So i should have 3 db tables in the database. and for example say 1 min, the Handler, result engin and the query engin should add a record to the db.

if is does not have a record in the db the haelth monitor figures out that the componenets have failed and bring the other instanse of the componenet up.

is this what hometownnerd suggested?

Member Avatar for LastMitch

I think hometownnerd mention 1 database and creating a query for health monitors to fetch the id.

So i should have 3 db tables in the database

You have 3 database or 3 tables relating to Handler, Result Engine and the Query Engine?

And each database has Handler, Result Engine and the Query Engine in it?

no no, sry
i was asking whether i should have 1 database and 3 tables for each class or

1 database with one table?

Member Avatar for LastMitch

i was asking whether i should have 1 database and 3 tables for each class or

1 database and 3 tables (Handler - 1 , Result Engine - 2 ,Query Engine - 3).

I think in long run this is the a better option if you need to update or add another class to the website.

hmm

so basically what i should do is add a record to the database updating the status of each class and then the health monitor checks the database regularly,

this method in the sense of performance and cost is expensive right? (because database access)
is there another way that i can do this increasing the performance?

if not i could use the database method
thanks

I would make a single table that would house all 3 of the handlers....in your table have a field called monitor, field called lastcheck....then row 1 could have handler in monitor field, row 2 could have result engine in monitor field and row 3 could have query engine in monitor field....then have class update lastcheck with now() anytime it fires depending on which class it would update the correct row. You could even start with the class updating the lastcheck field when it starts the run then have another field called status that could be populated at the end of the class with some sort of status to let you know the class started and completed. Simple and only needs a single table and could grow as handlers are needed and can even add other fields if you want to track other things in the class, like variables etc as the class fires.

Hope that helps,
Larry

commented: Nice Method. Learn something from you today. +11

so shoudn'there be a global timing system among the health monitor and the oth 3 calsses, how does it work

Yes you would need some sort of timer running on the system. Not sure what kind of system you have and what the ability of the servers are to determine what kind of timer you could potentially use, there are plenty of timer classes out there and you could have it fire when the app starts and then have the timer call itself after the set amount of time once it has completed firing. You could create 3 timers with different names so they would be independent. As far as code is concerned, not sure, but will look around. I use VB.Net for my server heartbeat app and I just placed 2 timers on the form to perform the datetime insert.

hope that helps a bit,
Larry

Here is a timer class for c#...I do not write c#, but it seems similar to the standard timer control....

using System;
using System.Timers;

class myApp
{
public static void Main()
{
Timer myTimerHandler = new Timer(); //this creates the timer control
myTimerHandler.Elapsed += new ElapsedEventHandler( TimeEventHandler ); //this builds the event that will fire when the timer trips....event is called "TimeEventHandler"
myTimerHandler.Interval = 1000; //this is the number of milliseconds between firings...1000 = 1 second....if you set this too low MAKE SURE YOU STOP THE TIMER first thing in the event
myTimerHandler.Start(); //this starts the timer so you can then watch the event

Timer myTimerResult = new Timer(); //this creates the timer control
myTimerResult.Elapsed += new ElapsedEventHandler( TimeEventResult ); //this builds the event that will fire when the timer trips....event is called "TimeEventResult"
myTimerResult.Interval = 1000; //this is the number of milliseconds between firings...1000 = 1 second....if you set this too low MAKE SURE YOU STOP THE TIMER first thing in the event
myTimerResult.Start(); //this starts the timer so you can then watch the event

Timer myTimerQuery = new Timer(); //this creates the timer control
myTimerQuery.Elapsed += new ElapsedEventHandler( TimeEventQuery ); //this builds the event that will fire when the timer trips....event is called "TimeEventQuery"
myTimerQuery.Interval = 1000; //this is the number of milliseconds between firings...1000 = 1 second....if you set this too low MAKE SURE YOU STOP THE TIMER first thing in the event
myTimerQuery.Start(); //this starts the timer so you can then watch the event


 }

public static void TimeEventHandler( object source, ElapsedEventArgs e )
{
myTimerHandler.Stop();//I think this is what you would do to stop the timer
// this is where you could call the class monitor

myTimerHandler.Start();//need to restart the timer before you leave the timer so it will fire again
  }
 }

 public static void TimeEventResult( object source, ElapsedEventArgs e )
{
myTimerHandler.Stop();//I think this is what you would do to stop the timer
// this is where you could call the class monitor

myTimerHandler.Start();//need to restart the timer before you leave the timer so it will fire again
  }
 }

 public static void TimeEventQuery( object source, ElapsedEventArgs e )
{
myTimerHandler.Stop();//I think this is what you would do to stop the timer
// this is where you could call the class monitor

myTimerHandler.Start();//need to restart the timer before you leave the timer so it will fire again
  }
 }

This may work for you...creates 3 timers and 3 events to handle the 3 monitor checks. I am not 100% sure in the code, but seems sound. One thing to keep an eye on is setting the interval too short where timers will fire again before the last timer has completed its work. That is why I placed the Stop and Start in the event. I pulled this from http://www.codeguru.com/csharp/sample_chapter/article.php/c7763/Working-with-a-Timer-in-C-The-Basics.htm

Let me know,
Larry

hey

in the method TimeEventHandler(), line myTimerHandler is underlined saying it is not identified in the current context, it gives the same msg to TimeEventResult() and TimeEventQuery()

how do i dolve this?
also how does the myApp communicate in updating the timer?i don't understand it.

appreciate a reply
thanks

Ok...here is updated class....like I said I am not a C# developer so it was rough around the edges...

using System;
using System.Timers;


    public class Class1
    {
        private static System.Timers.Timer myTimerHandler = new System.Timers.Timer(); //this creates the timer control
        private static System.Timers.Timer myTimerResult = new System.Timers.Timer(); //this creates the timer control
        private static System.Timers.Timer myTimerQuery = new System.Timers.Timer(); //this creates the timer control

public static void Main()
{

myTimerHandler.Elapsed += new ElapsedEventHandler( TimeEventHandler ); //this builds the event that will fire when the timer trips....event is called "TimeEventHandler"
myTimerHandler.Interval = 1000; //this is the number of milliseconds between firings...1000 = 1 second....if you set this too low MAKE SURE YOU STOP THE TIMER first thing in the event
myTimerHandler.Start(); //this starts the timer so you can then watch the event
myTimerResult.Elapsed += new ElapsedEventHandler( TimeEventResult ); //this builds the event that will fire when the timer trips....event is called "TimeEventResult"
myTimerResult.Interval = 1000; //this is the number of milliseconds between firings...1000 = 1 second....if you set this too low MAKE SURE YOU STOP THE TIMER first thing in the event
myTimerResult.Start(); //this starts the timer so you can then watch the event
myTimerQuery.Elapsed += new ElapsedEventHandler( TimeEventQuery ); //this builds the event that will fire when the timer trips....event is called "TimeEventQuery"
myTimerQuery.Interval = 1000; //this is the number of milliseconds between firings...1000 = 1 second....if you set this too low MAKE SURE YOU STOP THE TIMER first thing in the event
myTimerQuery.Start(); //this starts the timer so you can then watch the event
 }
public static void TimeEventHandler( object source, ElapsedEventArgs e )
{
myTimerHandler.Stop();//I think this is what you would do to stop the timer
// this is where you could call the class monitor
myTimerHandler.Start();//need to restart the timer before you leave the timer so it will fire again

 }
 public static void TimeEventResult( object source, ElapsedEventArgs e )
{

     myTimerResult.Stop();//I think this is what you would do to stop the timer
// this is where you could call the class monitor
    myTimerResult.Start();//need to restart the timer before you leave the timer so it will fire again

 }
 public static void TimeEventQuery( object source, ElapsedEventArgs e )
{
    myTimerQuery.Stop();//I think this is what you would do to stop the timer
// this is where you could call the class monitor
myTimerQuery.Start();//need to restart the timer before you leave the timer so it will fire again
  }

    }

As far as what is actually going to do the updating, I am unclear about what is doing the monitoring yet, the app that will be doing using the timers to update the DB will be running all of the time and you will start the timers on start and then the 3 timeevents will fire every however often and they will be in charge of sending the info to the db. You would put the health checks in those 3 timers to strobe the datetime etc into the DB. As far as deciding on the health, you would need to figure out how to do that based on your setup and the apps you have running, something must be running already to do the class work, this would be another layer on that. Not sure what you want to check yet.

Let me know,
Larry

hi larry is there any way that i can avoid the database, because i am trying to impleemnt this application considering performance.
Since there is database access each time to update the status i would think the perforamnce of the application would decrease,
thanks for the help

Honestly the inserts would not drain your performance very much, of course that depends on how often you do the checks....but once every 5 mins would not degrade performance. You could also have your check write an html file that you can get to from the web or intranet that displays the last run time of each of the checks. It would make a very simple html file something like

<html><head><meta http-equiv='refresh' content='60'></head><body><% =now()%></body></html>

That will display the last run time and also it will autorefresh every minute, you could then just watch that to make sure it is firing.

but honestly I do not think you will be paying much for the inserts into the DB.

Larry

It very usefull for me. Now I use VB.NET to coding but I can use this c# example as idea when coding. Thanks very very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.