当前位置:首页 > Windows程序 > 正文

driven communication c# program

2021-03-27 Windows程序

process communication can be analog to the theory of mobile network - there is a network that every subscriber can utilize to send and receive information.

of cause in program we should have resembles to network and user.

i have thought a lot on such kind of program implementation and structure, finally i found event driven or message driven is the best shape. to understand this concept one have to image there is a unique Centerlized static thing in your code - a postman. he is responsible for carrying everything for you and from you. there is no better choice. other implementation require tight coupling more or less, if every one talk to each other directly in code there should be at least n*(n-1) channel for this purpose. a centerlized - postman style - structure has a side good effect that it can written as message driven it mean the procedure can sleep until the message for him coming in. a static class called "Postman.cs" is defined in this quick demo written off duty tonight. this is also a must since every user want to see him clearly. this is a extreme situation where static class is the solution. i also wrote some Tcp class simulating Tcp communication mechanism, another Center.cs for simulating management entity since management part always have to look every thing. during implementation i found Broadcasting capability is the essence of communication protocol. in a microscopic view every communication path means a series of broadcasting in and only in useful scenario. since people have to register a mountain of handler function to the center. yes filter can be used to differentiate the sender object - but ovbiously i have to omit it for your dig. this is a working sample compile with vs2012 and run results as my expectation. it will be used in my machine talking project. which is on going. yeh.

here are output:

线程 ‘vshost.NotifyLoad‘ (0x2598) 已退出,返回值为 0 (0x0)。
线程 ‘<无名称>‘ (0x14c8) 已退出,返回值为 0 (0x0)。
线程 ‘<无名称>‘ (0x2570) 已退出,返回值为 0 (0x0)。
线程 ‘vshost.LoadReference‘ (0x2090) 已退出,返回值为 0 (0x0)。
“postman.vshost.exe”(托管(v4.0.30319)): 已加载“d:\mydocuments\visual studio 2012\Projects\postman\postman\bin\Debug\postman.exe”,符号已加载。
“postman.vshost.exe”(托管(v4.0.30319)): 已加载“C:\windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll”
OnSend->Civil Send out data
OnSend->System.EventArgs100
OnRecv->System.EventArgs123
OnRecv->System.EventArgs456
OnRecv->System.EventArgs789
OnRecv->System.EventArgs100
OnRecv->...
OnRecv->System.EventArgs100
OnSend->System.EventArgs123
OnSend->System.EventArgs456
OnSend->System.EventArgs789
OnSend->System.EventArgs100
OnRecv->...
OnRecv->System.EventArgs123
OnSend->System.EventArgs123
OnSend->System.EventArgs456
OnSend->System.EventArgs789
OnSend->System.EventArgs100
线程 ‘<线程结束>‘ (0x6c0) 已退出,返回值为 0 (0x0)。
OnRecv->...
OnRecv->System.EventArgs456
OnSend->System.EventArgs123
OnSend->System.EventArgs456
OnSend->System.EventArgs789
OnSend->System.EventArgs100
OnRecv->...
OnRecv->System.EventArgs789
OnSend->System.EventArgs123
OnSend->System.EventArgs456
OnSend->System.EventArgs789
OnSend->System.EventArgs100
OnSend->Tcp send->58
OnSend->System.EventArgs123
OnRecv->System.EventArgs123
OnRecv->System.EventArgs456
OnRecv->System.EventArgs789
OnRecv->System.EventArgs100
OnSend->Tcp send->59
OnSend->System.EventArgs456
OnRecv->System.EventArgs123
OnRecv->System.EventArgs456
OnRecv->System.EventArgs789
OnRecv->System.EventArgs100
OnSend->Tcp send->60
OnSend->System.EventArgs789
OnRecv->System.EventArgs123
OnRecv->System.EventArgs456
OnRecv->System.EventArgs789
OnRecv->System.EventArgs100
单步执行: 正在逐过程执行不含符号“Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly”的方法
线程 ‘vshost.RunParkingWindow‘ (0x14a0) 已退出,返回值为 0 (0x0)。
单步执行: 正在逐过程执行不含符号“System.Threading.ExecutionContext.RunInternal”的方法
线程 ‘<无名称>‘ (0x26e0) 已退出,返回值为 0 (0x0)。
程序“[9692] postman.vshost.exe: 托管(v4.0.30319)”已退出,返回值为 0 (0x0)。
程序“[9692] postman.vshost.exe: 程序跟踪”已退出,返回值为 0 (0x0)。


here are code plain text:

---------------------------------------

Postman.cs


namespace postman
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/68755.html