Position:Home>net development> The observer mode in Asp.net
The observer mode in Asp.net
From;  Author:Stand originally

Does observer mode come true in ASP.net? what does the observer mode in ASP.NET have special? Hum, the Application hard to avoid that is based on Http agreement is a little forgetful, I am such implementation, do not know to have better idea?

Talk about demand first, lest be immersed in theoretic

Recently a Case, such demand: End of a lot of clients is ceaseless submit data to Web Application, the administrator enters the administrative page of Web to be able to see these data immediately, many administrators can be browsed at the same time, and the data that the administrator scans begins to monitor that hour rises from the administrator, cannot show the data previously. Look from this setting, clear observer pattern, when the administrator begins to monitor, subscription data, when data arrives to all subscription the administrator broadcast data of data.

Demand pursues as follows:

Had the person that promulgator still needs subscription, we realize an administrator kind, will subscribe to data

Public Class Admin
{
/ **//// <summary>
/ / / the data that saves all receiving with this
/ / / </summary>Public IList<string>MessageList
{Get; Set; }Public Admin(Monitor Monitor)
{
MessageList = New List<string>();Monitor.DataIn = New EventHandler<DataEventArgs>(ReciveMessage);
}

Private Void ReciveMessage(object Sender, dataEventArgs E)


{

MessageList.Add(e.Message);

}

}

Ok, we had written the element that need has, but how to let their job rise? If make Winform program, that will be without be concerned about.

Analysis: The problem that we encounter

The first problem: When the client end sends package of a data, are we example changes a new Monitor? If be, which every time example changes a brand-new Monitor, all is in above it the incident of subscription will disappear entirely, how will if be this Monitor,exist? Always cannot vacuum, how is data saved between two Http request? Read demand again nevertheless, in be like whole application process, need to also can have a such Monitor only only, should be odd when mode enters the court.
Previous12 3 Next