using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
/*
C# IObservable与IObserver通知机制 观察者模式(推式模型)
*/
WeatherDataPublisher publisher = new WeatherDataPublisher();
CurrentConditionDisplay currentDisplay = new CurrentConditionDisplay();
StatisticsConditionDisplay statisticsDisplay = new StatisticsConditionDisplay();
//订阅当前天气展示板
IDisposable currentDisplayUnsubscriber = publisher.Subscribe(currentDisplay);
//订阅气温统计展示板
IDisposable statisticsDisplayUnsubscriber = publisher.Subscribe(statisticsDisplay);
for (int i = 0; ; i++)
{
WeatherData weatherData = new WeatherData();
C# IObservable与IObserver通知机制 观察者模式(推式模型)
最新推荐文章于 2024-06-14 23:12:07 发布
本文详细介绍了C#编程中IObservable和IObserver接口如何实现观察者模式,讨论了推式模型在事件通知中的应用,帮助开发者理解如何在C#中使用此设计模式进行异步通信。
摘要由CSDN通过智能技术生成