1

A lot has been said on argument of event-based loop, achieving parallelism and difference between Thread and Task<T>. I'd like to quote

What is the difference between task and thread?

that clearly explains how a Task<T> is a promise and the thread could be one of the means used to fulfil it.

This other question instead address the first point of the introduction

Is it possible in .NET, using C#, to achieve event based asynchronous pattern without multithreading?

Here come the question. I'm figuring how to design a reusable .NET infrastructural type(s) that can invoke a delegate when a particular event occur. Off course I've evaluated all reference supplied by the second question, but I feel that I still need to investigate more.

I'd like to achieve something like:

var sched = new Scheduler(new DefaultSchedulingStrategy());
var listnr = new TcpListener();
sched.DefineEventSource<Socket>(listnr.AcceptSocketAsync);
shed.OnEvent(
  (socket) = {
    // handling socket here
  });

I know that this seems very close to Task.Factory.FromAsync<T>. Anyway what I want to achieve here is also being able to change the scheduling strategy on different workloads and try to abstract as much as possible the logic that activates the event.

I've also considered writing a bare bone scheduler in F# (e.g. based on agents), create a C#-friendly reusable library and than code the rest of the server in C# (as it's my primary development language for the moment).

I hope I was clear enough (sorry but English is not my primary language).

Community
  • 1
  • 1
jay
  • 1,510
  • 2
  • 11
  • 19

1 Answers1

1

After I've learned about the wonderful world of Reactive Extensions, I'm always recommending them to everybody who wants to do something about complex events processing. There's also a very good introduction to this technology here. My guess it will be of a good use for your needs.

Haspemulator
  • 11,050
  • 9
  • 49
  • 76
  • {+1} @Haspemulator why this reply answer my question? *LinqRX* was the technology I'm thinking to use for such thing. I've explicitly non mentioned it (also if it's presented in the second quoted question) to get such confirmation. – jay Feb 18 '13 at 06:56
  • For reference I want to add the [Reactive Extensions](http://rx.codeplex.com/) are very very close to my sample. The library exposes also various scheduler with different threading models (read the online book suggested by @Haspemulator). Said that, [Extensions for Reactive Extensions](http://rxx.codeplex.com/) are another interesting project (the name is self-explanatory). For example it contains extension method to observe ``HttpListener``, ``TcpListener``, ``Sockets` and ``Streams`` (give a look at networking I/O on codeplex on the project wiki). Each developer should keep an eye on this. – jay Feb 19 '13 at 11:37
  • Agree, Rxx is important thing, but it's a pity that it's not a part of official Rx. Hopefully with migration to open-source model, Rx development speed will improve, and Rxx will become a part of it quickly. – Haspemulator Feb 19 '13 at 12:45