文章分类 - .NET
摘要:异步的目标不是为了让程序运行的更快,而是为了让资源物尽其用。如果你同步运行,wait()等,都会阻塞当前线程。当前线程不得不等待其他线程的任务完成后再继续执行,在这期间,当前线程没有任何用处,除了等待。这在客户端固然不算什么,客户端的计算能力足够,顶多是界面卡死一小会儿而已,但是在计算密集的服务器应
阅读全文
posted @ 2022-02-24 18:46
江境纣州
摘要:using StackExchange.Redis; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Configuration; using Syst
阅读全文
posted @ 2022-02-24 18:34
江境纣州
摘要:using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Newtonsoft.Json; using StackExchange.Redis; nam
阅读全文
posted @ 2022-02-24 18:33
江境纣州
摘要:1、ZipCompressionUtil using HRS.Lib.Comm.IO; using ICSharpCode.SharpZipLib.Checksums; using ICSharpCode.SharpZipLib.Zip; using System; using System.Col
阅读全文
posted @ 2022-02-24 18:10
江境纣州
摘要:1、值类型数组比较 int[] dataA = new int[] { 0, 1, 2, 3, 4, 5 }; int[] dataB = new int[] { 0, 1, 2, 4, 3, 5 }; List<int> dataC = new List<int> { 0, 1, 2, 3, 4,
阅读全文
posted @ 2022-02-24 15:58
江境纣州
摘要:var str = "abcDEF"; switch (str) { case string x when x.StartsWith("abc"): Console.WriteLine("abc"); break; case string x when x.StartsWith("efc"): Co
阅读全文
posted @ 2022-02-24 14:54
江境纣州
摘要:class Program { static void Main(string[] args) { for (int i = 0; i < 100; i++) { Thread t = new Thread(Test); t.Start(); } Console.Read(); } static v
阅读全文
posted @ 2022-02-23 17:03
江境纣州
摘要:异步操作时应注意的要点 使用异步方法返回值应避免使用void 对于预计算或者简单计算的函数建议使用Task.FromResult代替Task.Run 避免使用Task.Run()方法执行长时间堵塞线程的工作 避免使用Task.Result和Task.Wait()来堵塞线程 建议使用await来代替c
阅读全文
posted @ 2022-02-23 15:50
江境纣州
摘要:泛型作为参数和返回值 public static Func<T, R> Memoize<T, R>(Func<T, R> func) where T: IComparable { Dictionary<T, R> cache = new Dictionary<T, R>(); return arg
阅读全文
posted @ 2022-02-22 17:40
江境纣州
摘要:1、for循环:当闭包通过lambda表达式捕获可变变量时,lambda捕获变量的引用,而不是捕获该变量的当前值。因此,如果任务在变量的引用值更改后运行,则该值将是内存中最新的值,而不是捕获变量时的值。 for (int i = 0; i < 10; i++) { Task.Factory.Star
阅读全文
posted @ 2022-02-22 13:36
江境纣州
摘要:垃圾回收触发条件 CLR在检测到第0代超出预算时触发一次; 显式调用 System.GC.Collect 方法; Windows 通过Win32函数检测到内存低时触发; CLR 正在卸载 AppDomain 时(一个AppDomain卸载时,CLR认为其中一切都不是根,执行一次涵盖所有代的GC);
阅读全文
posted @ 2022-02-22 11:15
江境纣州
摘要:public static class Program { public static void Main() { // 创建每2000ms就调用一次 TimerCallBack 方法的 Timer 对象 Timer t = new Timer(TimerCallBack, null, 0, 200
阅读全文
posted @ 2022-02-22 10:35
江境纣州
摘要:参考https://blog.csdn.net/weixin_39328209/article/details/105945778?spm=1001.2014.3001.5502 它可以回收不在根表中直接或间接引用的托管内存。 然而,有时可能会忘记释放引用。 注意:如果对象互相引用,但没有在根表中引
阅读全文
posted @ 2022-02-22 10:23
江境纣州
摘要:css 参考https://gitee.com/zTree/zTree_v3/blob/master/css/zTreeStyle/zTreeStyle.css js参考https://gitee.com/zTree/zTree_v3/blob/master/js/jquery.ztree.all.
阅读全文
posted @ 2022-02-21 16:18
江境纣州
摘要:一、内存泄漏 在类型安全的代码,一般内存不会被破坏,但是也可能造成内存泄漏的情况: 1、在集合中添加对象,即使这些对象不被使用,也不回收。 2、静态字段引用某个集合对象,然后往集合里添加数据。 二、new托管堆分配对象 1、进程初始化时,CLR划分一块地址空间作为托管堆,如果托管堆被非垃圾对象填满后
阅读全文
posted @ 2022-02-11 10:03
江境纣州
摘要:6.1、简介 ConcurrentQueue:队列(Cas原子比较和交换)、ConcurrentStack:堆栈(Cas原子比较和交换)、ConcurrentBag:支持重复的无序集合 避免使用Count,复杂度O(N),IsEmpty属性是O(1)。 ConncurrentDictionary:字
阅读全文
posted @ 2022-02-08 16:54
江境纣州
摘要:1、Thread.Sleep是同步延迟、Task.Delay是异步延迟 2、Thread.Sleep会阻塞线程,Task.Delay不会阻塞线程。 3、Thread.Sleep不能取消,Task.Delay可以取消。 4、Task.Delay会比Thread.Sleep更消耗资源,Task.Dela
阅读全文
posted @ 2022-01-27 17:32
江境纣州
摘要:1、异步函数async 1)、异步函数需要使用async关键词标注方法,异步函数必须返回Task或Task<int>,可以使用async void方法(唯一合理在程序UI控制器事件处理器中),其余更推荐async Task。 2)、async方法内部,可以使用await操作符,在async外不能使用
阅读全文
posted @ 2022-01-27 16:36
江境纣州
摘要:string.Format("{0,-50}", theObj);//格式化成50个字符,原字符左对齐,不足则补空格 string.Format("{0,50}", theObj);//格式化成50个字符,原字符右对齐,不足则补空格 Console.WriteLine("{0} with{1,11}
阅读全文
posted @ 2022-01-20 14:19
江境纣州
摘要:1、实现 static void Main(string[] args) { Thread thread = new Thread(PrintNumbers); thread.Start(); PrintNumbers(); Console.Read(); } static void PrintNu
阅读全文
posted @ 2022-01-20 11:32
江境纣州

浙公网安备 33010602011771号