简体   繁体   中英

Design a modular delegate scheduler for server architecture

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# (eg 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 ).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM