随笔分类 - .NET / C#
摘要:https://stackoverflow.com/questions/9271805/net-module-vs-assembly In .net the difference between an assembly and module is that a module does not con
阅读全文
摘要:什么是枚举 the action of mentioning a number of things one by one 枚举的意思就是一个接一个提及一系列事物。 其中,这些事物需要有名字,才能被提及。以及需要有唯一标识该事物的方法。 形式一:Enum类 官方的枚举类型是最常用的枚举。每个枚举会生成
阅读全文
摘要:stackalloc 官方文档 https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/stackalloc A stackalloc expression allocates a block of m
阅读全文
摘要:### 简介 想对单例进行统一的管理,在UnityEditor[进入playMode](https://docs.unity.cn/2019.4/Documentation/ScriptReference/EditorApplication-playModeStateChanged.html)的时候
阅读全文
摘要:https://stackoverflow.com/questions/10196897/memorymappedfile-createoropen-throws-the-handle-is-invalid C# mutex的名字和 MemoryMappedFile名字不能一样。。 可能是底层用到了
阅读全文
摘要:[内存映射文件(Memory-mapped files)](https://learn.microsoft.com/en-us/dotnet/standard/io/memory-mapped-files)是一种很好的进程间通信方式,它暴露了底层的细节,具有很强的扩展性以及性能。  ```C# using System.Collections; using Syste
阅读全文
摘要:### 起因 C#函数中没有显示native线程id的,只能显示managedThreadId,如果想显示nativeThreadId就需要通过[PInvoke](https://learn.microsoft.com/zh-cn/dotnet/standard/native-interop/pin
阅读全文
摘要:https://github.com/dotnet/sdk/issues/16975 >6bee commented on Apr 1 > adding the following PropertyGroup to the .pubxml seems to have solved the issue
阅读全文
摘要:```C# public static bool TryGetLocalEndPoint(out IPEndPoint ipEndPoint) { try { string localIP = string.Empty; using (Socket socket = new Socket(Addre
阅读全文
摘要:转发自 https://www.cnblogs.com/walterlv/p/10236378.html `CommandLineParser` 是一款用于解析命令行参数的 NuGet 包。你只需要关注你的业务,而命令行解析只需要极少量的配置代码。 本文将介绍如何使用 `CommandLinePar
阅读全文
摘要:### 问题 对于泛型类`List`,如果调用`type.FullName`和`type.Name`会分别返回下面的内容。 ```C# //type.FullName System.Collections.Generic.List`1[[System.Int32, mscorlib, Version
阅读全文
摘要:while (true) { byte[] bytes = UdpClient.Receive(ref remoteEndPoint); NetMessage netMessage = NetMessage.Parse(new ArraySegment<byte>(bytes)); OnReceiv
阅读全文
摘要:https://www.cnblogs.com/zeroone/p/3766247.html [Flags] public enum ProcessAccessFlags : uint { All = 0x001F0FFF, Terminate = 0x00000001, CreateThread
阅读全文
摘要:C#和C++的交互如果自己写代码,一方面繁琐,另一方面容易出错,再者就是代码不太规范。 最近看了一下PInvoke.net的东西,可以直接使用官方写好的。 下面是使用Pinvoke.net打开设备的一个例子。 private void openDeviceButton_Click(object se
阅读全文
摘要:https://learn.microsoft.com/en-us/archive/msdn-magazine/2017/may/net-core-cross-platform-code-generation-with-roslyn-and-net-core https://www.tugberku
阅读全文
摘要:C#的序列化库很多通过注解Attribute来实现,比如Protobuf-net,Messagepack等。如果手动添加注解,会比较麻烦,尤其在切换序列化库的时候,需要更改对应的注解。 这里实现了一个使用Mono.Cecil来自动添加注解的类,当程序编译后,会修改对应的dll来实现效果。 遇到的坑:
阅读全文
摘要:最近用反射,想找到一个接口的父接口,发现baseType是null。 但是dotpeek反射里面显示是有baseType的。 搜了一下,意识到你只能 implement 一个接口,而不能inherit一个接口。所以一个接口想找到父接口应该再次使用GetInterfaces函数。
阅读全文
摘要:简介 不管是RPC还是IPC,本质都是通过某种寻址方式调用另一个**工作单元(线程)**的函数(subroutine)。 此处工作单元可以是主机(host),进程(process),线程(thread)。最终函数将在某个主机上的某个进程里的某个线程中执行。 为了简化情况,我们假设一台主机上只运行一个
阅读全文
摘要:网络发送数据包,现成的接口Socket.Send在我的电脑上大概会有700us左右的耗时,如果使用SendAsync开销会更大,并且会导致数据包的乱序。 Send阻塞接口慢的原因一方面底层会跑很多代码,另一方面有线程就有竞争,有竞争就有加锁。 于是写了一个轻量的Queue来加速网络发包,平均耗时从7
阅读全文