---
title: "Reactive Extensions (Rx) - Part 1 - Replacing C# Events - Muhammad Rehan Saeed"
description: "You should definitely consider using Reactive Extensions (Rx) is as a direct replacement for C# events. This post will explain how."
canonical_url: "https://rehansaeed.com/reactive-extensions-part1-replacing-events/"
last_updated: "2014-02-11T00:00:00+00:00"
meta:
  author: "Muhammad Rehan Saeed"
  keywords: ".NET,C#,Events,Reactive Extensions,Rx"
  "og:description": "You should definitely consider using Reactive Extensions (Rx) is as a direct replacement for C# events. This post will explain how."
  "og:image": "https://rehansaeed.com/_og/s/o_5d50081d662265d5.png"
  "og:image:alt": "Reactive Extensions (Rx) - Part 1 - Replacing C# Events - Muhammad Rehan Saeed"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Reactive Extensions (Rx) - Part 1 - Replacing C# Events"
  "twitter:image": "https://rehansaeed.com/_og/s/o_5d50081d662265d5.png"
  "twitter:image:alt": "Reactive Extensions (Rx) - Part 1 - Replacing C# Events - Muhammad Rehan Saeed"
---

> Index of every page on this site: [llms.txt](https://rehansaeed.com/llms.txt)

# [Reactive Extensions (Rx) - Part 1 - Replacing C# Events](https://rehansaeed.com/reactive-extensions-part1-replacing-events/)

Posted 11 February 2014 - **4 min read**

![Reactive Extensions](https://rehansaeed.com/_ipx/f_webp&s_2560x1440/images/hero/Reactive-Extensions-1366x768.png)

1. [Reactive Extensions (Rx) - Replacing C# Events](https://rehansaeed.com/reactive-extensions-part1-replacing-events/)
2. [Reactive Extensions (Rx) - Wrapping C# Events](https://rehansaeed.com/reactive-extensions-part2-wrapping-events/)
3. [Reactive Extensions (Rx) - Naming Conventions](https://rehansaeed.com/reactive-extensions-part3-naming-conventions/)
4. [Reactive Extensions (Rx) - Replacing Timers](https://rehansaeed.com/reactive-extensions-part4-replacing-timers/)
5. [Reactive Extensions (Rx) - Awaiting Observables](https://rehansaeed.com/reactive-extensions-part5-awaiting-observables/)
6. [Reactive Extensions (Rx) - Task ToObservable](https://rehansaeed.com/reactive-extensions-part6-task-toobservable/)
7. [Reactive Extensions (Rx) - Sample Events](https://rehansaeed.com/reactive-extensions-part7-sample-events/)
8. [Reactive Extensions (Rx) - Timeouts](https://rehansaeed.com/reactive-extensions-rx-part-8-timeouts/)

For those who have not tried Reactive Extensions (Rx) yet, I highly recommend it. If I had to describe it in a few words it would be 'Linq to events'. If you have not already learned about it, [this](http://www.introtorx.com/uat/content/v1.0.10621.0/00_Foreword.html) is by far the best resource on learning its intricacies.

I have spent a lot of time reading about Reactive Extensions but what I have not found in my research is examples or pointers on how or even where it should be used in preference to other code. One area where you should definitely consider using Reactive Extensions is as a direct replacement for bog standard C# events, which have been around since C# 1.0. This post will explain how.

# Exposing an Event

Here is an example of a standard C# event using the standard recommended pattern:

```cs
public class JetFighter
{
    public event EventHandler<JetFighterEventArgs> PlaneSpotted;

    public void SpotPlane(JetFighter jetFighter)
    {
        EventHandler<JetFighterEventArgs> eventHandler = this.PlaneSpotted;
        if (eventHandler != null)
        {
            eventHandler(this, new JetFighterEventArgs(jetfighter));
        }
    }
}
```

Now this is how you replace it using Reactive Extensions:

```cs
public class JetFighter
{
    private Subject<JetFighter> planeSpotted = new Subject<JetFighter>();

    public IObservable<JetFighter> PlaneSpotted => this.planeSpotted.AsObservable();

    public void SpotPlane(JetFighter jetFighter) => this.planeSpotted.OnNext(jetFighter);
}
```

So far it's all pretty straightforward, we have replaced the event with a property returning `IObservable<T>`. Raising the event is a simple matter of calling the `OnNext` method on the Subject class. Finally, we do not return our `Subject<T>` directly in our `PlaneSpotted` property, as someone could cast it back to `Subject<T>` and raise their own events! Instead we use the `AsObservable` method which returns a middle man. So far so good.

Reactive Extensions also has the added concept of errors and completion, which C# events do not have. These are optional added concepts and not required for replacing C# events directly but worth knowing about, as they add an extra dimension to events which may be useful to you.

The first concept is dealing with errors. What happens if there is an exception while you are spotting the plane and you want to notify your subscribers that there is a problem? Well you can do that, like this:

```cs
public void SpotPlane(JetFighter jetFighter)
{
    try
    {
        if (string.Equals(jetFighter.Name, "UFO"))
        {
            throw new Exception("UFO Found")
        }

        this.planeSpotted.OnNext(jetFighter);
    }
    catch (Exception exception)
    {
        this.planeSpotted.OnError(exception);
    }
}
```

Here we are using the `OnError` method to notify all the events subscribers that there has been an exception.

So what about the concept of completion? Well, that's just as simple. Suppose that you have spotted all the planes and you want to notify all your subscribers that there will be no more spotted planes. You can do that like this:

```cs
public void AllPlanesSpotted() => this.planeSpotted.OnCompleted();
```

So now all the code put together looks like this:

```cs
public class JetFighter
{
    private Subject<JetFighter> planeSpotted = new Subject<JetFighter>();

    public IObservable<JetFighter> PlaneSpotted => this.planeSpotted;

    public void AllPlanesSpotted() => this.planeSpotted.OnCompleted();

    public void SpotPlane(JetFighter jetFighter)
    {
        try
        {
            if (string.Equals(jetFighter.Name, "UFO"))
            {
                throw new Exception("UFO Found")
            }

            this.planeSpotted.OnNext(jetFighter);
        }
        catch (Exception exception)
        {
            this.planeSpotted.OnError(exception);
        }
    }
}
```

# Consuming an Event

Consuming the Reactive Extensions events is just as easy and this is where you start to see the real benefits of Reactive Extensions. This is how you subscribe and unsubscribe (often forgotten, which can lead to memory leaks) to a standard C# event:

```cs
public class BomberControl : IDisposable
{
    private JetFighter jetfighter;

    public BomberControl(JetFighter jetFighter) =>
        jetfighter.PlaneSpotted += this.OnPlaneSpotted;

    public void Dispose() =>
        jetfighter.PlaneSpotted -= this.OnPlaneSpotted;

    private void OnPlaneSpotted(object sender, JetFighterEventArgs e) =>
        JetFighter spottedPlane = e.SpottedPlane;
}
```

I'm not going to go into it in too much detail, you subscribe using `+=` and unsubscribe using `-=` operators.

This is how the same thing can be accomplished using Reactive Extensions:

```cs
public class BomberControl : IDisposable
{
    private IDisposable planeSpottedSubscription;

    public BomberControl(JetFighter jetFighter) =>
        this. planeSpottedSubscription = jetfighter.PlaneSpotted.Subscribe(this.OnPlaneSpotted);

    public void Dispose() =>
        this.planeSpottedSubscription.Dispose();

    private void OnPlaneSpotted(JetFighter jetFighter) =>
        JetFighter spottedPlane = jetfighter;
}
```

The key things to note here are first, the use of the `Subscribe` method to register for plane spotted events. Second, the subscription to the event is stored in an `IDisposable` which can later be disposed of, to un-register from the event. This is where things get interesting, since we now have an `IObservable<T>` we can now use all kinds of Linq queries on it like this:

```cs
jetfighter.PlaneSpotted.Where(x => string.Equals(x.Name, “Eurofighter”)).Subscribe(this.OnPlaneSpotted);
```

So in the above line of code, I'm using a Linq query to only register to events where the name of the spotted plane is `Eurofighter`. There are a lot more Linq methods you can use but that's beyond the scope of this post and also where you should take a look at [this website](http://www.introtorx.com/uat/content/v1.0.10621.0/00_Foreword.html).

# Conclusions

Reactive Extensions (Rx) is a pretty large library which does a lot of stuff which overlaps with other libraries like the Task Parallel Library (TPL). It brings no new capabilities but does bring new ways to do things (much like Linq), while writing less code and with more elegance. It can be confusing coming to it as a newcomer, as to where exactly it can be used effectively. Replacing basic events with `IObservable<T>` is definitely one area where we can leverage its power.

## Web Mentions

[What's this?](https://en.wikipedia.org/wiki/Webmention)

### 0 Linked

### 0 Replies

## GitHub Comments

### 15 Comments

[Comment on GitHub](https://github.com/RehanSaeed/rehansaeed.github.io/issues/103)

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Tony](https://camo.githubusercontent.com/4408e8a1e4c33f65b5f3609854b45dd86f25405155ccbc343274ad3afd5ff56f/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f36383635373238326566313866343934326338616239313737303537643837363f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/4408e8a1e4c33f65b5f3609854b45dd86f25405155ccbc343274ad3afd5ff56f/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f36383635373238326566313866343934326338616239313737303537643837363f733d393626643d6d6d26723d67) **[Tony](http://tonytruong.net/)** commented on **2014-10-24 00:36:27**

Thanks for that. Very helpful in seeing the bigger picture.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![jacob](https://camo.githubusercontent.com/f85383816c3018f0f39ff929d628b75a9b747a5ecbdd7d9006ae27f834d30100/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f63363061386237636432623439336235613237323437363063343333373037363f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/f85383816c3018f0f39ff929d628b75a9b747a5ecbdd7d9006ae27f834d30100/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f63363061386237636432623439336235613237323437363063343333373037363f733d393626643d6d6d26723d67) **jacob** commented on **2014-12-23 17:06:30**

Great blog! thanks for the help, makes alot more sense now

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Abhinav Singh](https://camo.githubusercontent.com/d5652105f984dbb5eab267c12479471ad838e94ccd696ea7709ea8a939bf7bd1/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f36326232356463666666333934653765666633303035383335386237353034373f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/d5652105f984dbb5eab267c12479471ad838e94ccd696ea7709ea8a939bf7bd1/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f36326232356463666666333934653765666633303035383335386237353034373f733d393626643d6d6d26723d67) **Abhinav Singh** commented on **2015-03-06 17:58:38**

```
public void SpotPlane(JetFighter jetFighter)
{
    try
    {
        if (string.Equals(jetFighter.Name, "UFO"))
        {
            throw new Exception("UFO Found")
        }
        this.planeSpotted.OnNext(foo);
    }
    catch (Exception exception)
    {
        this.planeSpotted.OnError(exception);
    }
}
```

In above code, we should have `this.planeSpotted.OnNext(jetFighter);` instead of `this.planeSpotted.OnNext(foo);`?  
 My understanding is correct?  
 Please reply

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020 (edited 12 May 2020)

[![Muhammad Rehan Saeed](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67) **[Muhammad Rehan Saeed](https://rehansaeed.com/)** commented on **2015-03-06 19:15:57**

> ```
> public void SpotPlane(JetFighter jetFighter)
> {
>     try
>     {
>         if (string.Equals(jetFighter.Name, "UFO"))
>         {
>             throw new Exception("UFO Found")
>         }
>         this.planeSpotted.OnNext(foo);
>     }
>     catch (Exception exception)
>     {
>         this.planeSpotted.OnError(exception);
>     }
> }
> ```
>
> In above code, we should have `this.planeSpotted.OnNext(jetFighter);` instead of `this.planeSpotted.OnNext(foo);`?  
>  My understanding is correct?  
>  Please reply

Yes that's correct. I've now corrected it.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Reader Man](https://camo.githubusercontent.com/51f3cb181e7e5588900f79a157b11303ac93e43d0621a567b60ed3425049134d/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f66616564323264626635666464393333633061346131353139623932323338323f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/51f3cb181e7e5588900f79a157b11303ac93e43d0621a567b60ed3425049134d/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f66616564323264626635666464393333633061346131353139623932323338323f733d393626643d6d6d26723d67) **[Reader Man](http://readerman1.wordpress.com/)** commented on **2016-06-04 14:53:49**

Thanks a lot on this series.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Sam](https://camo.githubusercontent.com/687870a135f2a582765906e66dd7846dd7353ff4a211e3622dcf05c948898b30/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f38353433306331623639346232633161653137313066636634613465663232373f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/687870a135f2a582765906e66dd7846dd7353ff4a211e3622dcf05c948898b30/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f38353433306331623639346232633161653137313066636634613465663232373f733d393626643d6d6d26723d67) **Sam** commented on **2016-08-17 15:45:07**

When is this called?

```
public void AllPlanesSpotted()
{
    this.planeSpotted.OnCompleted();
}
```

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Muhammad Rehan Saeed](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67) **[Muhammad Rehan Saeed](https://rehansaeed.com/)** commented on **2016-08-19 09:18:50**

> When is this called?
>
> ```
> public void AllPlanesSpotted()
> {
>     this.planeSpotted.OnCompleted();
> }
> ```

I'm just trying to illustrate that observables can have an end, so that no more events are allowed to be raised. It could be called from anywhere.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Andrey](https://camo.githubusercontent.com/cb55fe2d2a62c0daaeab2c15fdc991c02e64610093723ce906e16b0ec66f26c6/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f39346137363139393038343537613563383661663362636261626136366632333f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/cb55fe2d2a62c0daaeab2c15fdc991c02e64610093723ce906e16b0ec66f26c6/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f39346137363139393038343537613563383661663362636261626136366632333f733d393626643d6d6d26723d67) **Andrey** commented on **2017-01-06 12:48:07**

"Intro to Rx" says that using subjects is discouraged, because they are only for playing, they "introduce mutability", may have bad performance in future releases, etc.

The question is: how do I then implement a Rx equivalent of C# events? Implementing a c# event then using `FromEventPattern` seems cumbersome, subjects are "discouraged" what do I use then?

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Muhammad Rehan Saeed](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67) **[Muhammad Rehan Saeed](https://rehansaeed.com/)** commented on **2017-01-07 11:10:34**

> "Intro to Rx" says that using subjects is discouraged, because they are only for playing, they "introduce mutability", may have bad performance in future releases, etc.
>
> The question is: how do I then implement a Rx equivalent of C# events? Implementing a c# event then using FromEventPattern seems cumbersome, subjects are "discouraged" what do I use then?

I've read that too, one of the problems is that you can both publish and subscribe to it which can be dangerous. You hit the nail on the head, how else would you implement events without it? I take the more pragmatic approach. I know the potential pitfalls of using it, I know not to expose the subject outside of the class using it, so I use it.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Andrey](https://camo.githubusercontent.com/cb55fe2d2a62c0daaeab2c15fdc991c02e64610093723ce906e16b0ec66f26c6/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f39346137363139393038343537613563383661663362636261626136366632333f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/cb55fe2d2a62c0daaeab2c15fdc991c02e64610093723ce906e16b0ec66f26c6/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f39346137363139393038343537613563383661663362636261626136366632333f733d393626643d6d6d26723d67) **Andrey** commented on **2017-01-08 13:25:01**

> I've read that too, one of the problems is that you can both publish and subscribe to it which can be dangerous. You hit the nail on the head, how else would you implement events without it? I take the more pragmatic approach. I know the potential pitfalls of using it, I know not to expose the subject outside of the class using it, so I use it.

I see, these rumours about subjects are mostly about functional programming ideas. For those who just want a substitute for dumb C# events, `Subject` is just right.

Found a good explanation on when to use `Subject`:  
http://davesexton.com/blog/post/To-Use-Subject-Or-Not-To-Use-Subject.aspx

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Jesse Liberty](https://camo.githubusercontent.com/ad823f62b334449081f4ba2981c781d98dadc4a0bf1425dcdb4b917b97b8d8e5/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f37386435623636303966653561383063653637653966393731383333613663333f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/ad823f62b334449081f4ba2981c781d98dadc4a0bf1425dcdb4b917b97b8d8e5/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f37386435623636303966653561383063653637653966393731383333613663333f733d393626643d6d6d26723d67) **[Jesse Liberty](http://jesseliberty.com/)** commented on **2017-01-16 14:08:33**

You may want to take a quick look at http://jliberty.me/2j0ePAP -- thanks

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![HMIndia](https://camo.githubusercontent.com/a41382bc67b28469c78d7cf834df1e37bdcc6aa6ed8ef160be936275c7280dea/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f62623831346433346432346562326436323562666539623565666239313265643f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/a41382bc67b28469c78d7cf834df1e37bdcc6aa6ed8ef160be936275c7280dea/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f62623831346433346432346562326436323562666539623565666239313265643f733d393626643d6d6d26723d67) **[HMIndia](https://hemantmahajan08.wordpress.com/)** commented on **2018-10-18 09:01:35**

In High refresh applications (say Stock market) can we claim that use of RX will improve the performance and memory management

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Muhammad Rehan Saeed](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67) **[Muhammad Rehan Saeed](https://rehansaeed.com/)** commented on **2018-10-23 09:48:04**

> In High refresh applications (say Stock market) can we claim that use of RX will improve the performance and memory management

I don't think you can claim that without building it and measuring the difference.

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![DanClark](https://camo.githubusercontent.com/3430e14ebbdaf0c7e8e14f7681265470028662537f0b6b4f9e8c09a99efeb1eb/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f65393330653831383165336331633662353666383439323432643166373161343f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/3430e14ebbdaf0c7e8e14f7681265470028662537f0b6b4f9e8c09a99efeb1eb/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f65393330653831383165336331633662353666383439323432643166373161343f733d393626643d6d6d26723d67) **DanClark** commented on **2019-10-08 21:31:58**

Hi,

I followed your example, are you able to answer this question by any chance?  
https://stackoverflow.com/questions/58263480/reactive-extension-simple-example-not-working-with-number-generator

Thanks,

[![RehanSaeed](https://avatars.githubusercontent.com/u/2270364?v=4)](https://github.com/RehanSaeed "RehanSaeed")

### [RehanSaeed](https://github.com/RehanSaeed)

Owner

12 May 2020

[![Muhammad Rehan Saeed](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67)](https://camo.githubusercontent.com/8a07049df41b8a3839a3f4342f09ea8e6e7fa0065667687f04beca2d088a1dca/68747470733a2f2f7777772e67726176617461722e636f6d2f6176617461722f32623266393030653361633066353535316462646537323864336262343935343f733d393626643d6d6d26723d67) **[Muhammad Rehan Saeed](https://rehansaeed.com/)** commented on **2019-10-10 20:17:12**

> Hi,
>
> I followed your example, are you able to answer this question by any chance?  
> https://stackoverflow.com/questions/58263480/reactive-extension-simple-example-not-working-with-number-generator
>
> Thanks,

That's great! StackOverflow is a great place to ask questions. Have an upvote.

I had a quick look. You say it doesn't work but don't describe what the problem is, what do you expect and what actually happens.

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://rehansaeed.com/#website","@type":"WebSite","description":"Software Developer at Microsoft, YouTuber, Open Source Contributor and Blogger","inLanguage":"en-GB","name":"Muhammad Rehan Saeed","url":"https://rehansaeed.com/","author":{"@id":"https://rehansaeed.com/#identity"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://rehansaeed.com/?search={search_term_string}"},"query-input":"required name=search_term_string"}],"publisher":{"@id":"https://rehansaeed.com/#publisher"}},{"@id":"https://rehansaeed.com/reactive-extensions-part1-replacing-events/#webpage","@type":"WebPage","dateModified":"2014-02-11T00:00:00+00:00","datePublished":"2014-02-11T00:00:00+00:00","description":"You should definitely consider using Reactive Extensions (Rx) is as a direct replacement for C# events. This post will explain how.","name":"Reactive Extensions (Rx) - Part 1 - Replacing C# Events","url":"https://rehansaeed.com/reactive-extensions-part1-replacing-events/","breadcrumb":{"@id":"https://rehansaeed.com/reactive-extensions-part1-replacing-events/#breadcrumb"},"isPartOf":{"@id":"https://rehansaeed.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://rehansaeed.com/reactive-extensions-part1-replacing-events/"]}]},{"@id":"https://rehansaeed.com/#identity","@type":"Person","name":"Muhammad Rehan Saeed","url":"https://rehansaeed.com/about/","image":{"@id":"https://rehansaeed.com/#/schema/image/1"},"sameAs":["https://github.com/RehanSaeed","https://www.linkedin.com/in/muhammad-rehan-saeed","https://stackoverflow.com/users/1212017/muhammad-rehan-saeed","https://www.youtube.com/c/MuhammadRehanSaeed","https://www.twitch.tv/rehansaeeduk"]},{"@id":"https://rehansaeed.com/#publisher","@type":"Organization","logo":"https://rehansaeed.com/images/schema/Publisher-600x60.png","name":"Muhammad Rehan Saeed","url":"https://rehansaeed.com"},{"@id":"https://rehansaeed.com/reactive-extensions-part1-replacing-events/#article","@type":"Article","dateModified":"2014-02-11T00:00:00+00:00","datePublished":"2014-02-11T00:00:00+00:00","description":"You should definitely consider using Reactive Extensions (Rx) is as a direct replacement for C# events. This post will explain how.","headline":"Reactive Extensions (Rx) - Part 1 - Replacing C# Events","inLanguage":"en-GB","url":"https://rehansaeed.com/reactive-extensions-part1-replacing-events/","author":{"@id":"https://rehansaeed.com/#identity"},"image":[{"@type":"ImageObject","url":"https://rehansaeed.com/images/hero/Reactive-Extensions-1366x768.png","caption":"Reactive Extensions","width":"1366","height":"768"}],"isPartOf":{"@id":"https://rehansaeed.com/reactive-extensions-part1-replacing-events/#webpage"},"keywords":[".NET","C#","Events","Reactive Extensions","Rx"],"mainEntityOfPage":{"@id":"https://rehansaeed.com/reactive-extensions-part1-replacing-events/#webpage"},"publisher":{"@id":"https://rehansaeed.com/#publisher"}},{"@id":"https://rehansaeed.com/reactive-extensions-part1-replacing-events/#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Blog","item":"https://rehansaeed.com/","position":1},{"@type":"ListItem","name":"Reactive Extensions (Rx) - Part 1 - Replacing C# Events","item":"https://rehansaeed.com/reactive-extensions-part1-replacing-events/","position":2}]},{"@id":"https://rehansaeed.com/#/schema/image/1","@type":"ImageObject","contentUrl":"https://rehansaeed.com/images/author/Muhammad-Rehan-Saeed/Logo-512x512.png","inLanguage":"en-GB","url":"https://rehansaeed.com/images/author/Muhammad-Rehan-Saeed/Logo-512x512.png"}]}
```

## Sitemap

See the full [sitemap](https://rehansaeed.com/sitemap.md) for all pages.
