摘要:研究如下问题: 1. 在一个进程的主线程中创建一个Object,其他线程都可以访问这个Object,并操作Object的方法。 - 多线程同步问题。 2. 在一个进程的多个线程里面,每个线程都创建同一个Class的Object,并操作Object的方法。 - 会有同步问题吗,如果这个Object是个
阅读全文
随笔分类 - C#/.NET
摘要:参考: https://stackoverflow.com/questions/154551/volatile-vs-interlocked-vs-lock/154803
阅读全文
摘要:需求是将一个string 表达式 转换成 逻辑 表达式 并得到结果。 例如: bool result = (key1==val1) || (key2!=val2) && (key3==val3). 其中 keyN, valN 均为变量。 基本的思路是先做Express string 验证,然后进行解
阅读全文
摘要:What does the underscore mean in the following regex? [a-zA-Z0-9_] It means to match the underscore character in addition to lowercase letters, upperc
阅读全文
摘要:有个case,对一个double数设置初始值,然后,在程序运行中,为double赋值。(注意,也可能没有赋值)。 这个时候,可以用Nullable 来设置初始值,在程序的最后做个判断。 参考:
阅读全文
摘要:多线程编程中要注意对线程异常的处理。首先写个例子。一个线程用于显示信息(Show Messages)。主线程用于做其他工作(Do Works)。 using (Task taskShowMessages = new Task(ShowMessages)) ...
阅读全文
摘要:Get Files from Directory [C#]This example shows how to get list of file names from a directory (including subdirectories). You can filter the list by ...
阅读全文
摘要:参考:https://msdn.microsoft.com/en-us/library/x13ttww7(VS.80).aspxhttp://stackoverflow.com/questions/2474945/is-it-safe-to-use-a-boolean-flag-to-stop-a-...
阅读全文
摘要:.NET 4.0 requires XP SP3, Win2k3 SP2, Vista, 7, or 2008(R2).NET 3.5 requires XP SP2 or newer..NET 2.0 requires Win2K SP(3?) or newer.Incidentally, XP ...
阅读全文
摘要:在VS2012中的右键中没有发现"Create Unit Test" 选项,原来需要安装个补丁:https://visualstudiogallery.msdn.microsoft.com/45208924-e7b0-45df-8cff-165b505a38d7?SRC=Home参考:http://...
阅读全文
摘要:C# Lock原文:http://www.dotnetperls.com/lockLocking is essential in threaded programs. It restricts code from being executed by more than one thread at t...
阅读全文
摘要:Finally ,找到工具来参考转换。 Source: https://github.com/jaredpar/pinvokeTool: https://archive.codeplex.com/?p=clrinterop 书籍 参考: NET and COM: The Complete Inter
阅读全文
摘要:http://yoda.arachsys.com/csharp/parameters.html
阅读全文
摘要:C#动态调用C++编写的DLL函数动态加载DLL需要使用Windows API函数:LoadLibrary、GetProcAddress以及FreeLibrary。我们可以使用DllImport在C#中使用这三个函数。[DllImport("Kernel32")]public static exte...
阅读全文
摘要:在VS2012里面,右击需要发布的Project,选择“Properties“, 在弹出的窗口里面点选”Publish“, 再点击”Application Files“,将默认的Publish Status列的”Data File(Auto)“改成 ”Include“。另外, 对需要copy到bui...
阅读全文
摘要:private string GetCurrentDateTime() { return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss "); }如果想显示毫秒的话, format 里面添加 为...
阅读全文
摘要:值类型直接用 == 号判断就好。但是对于引用类型,需要实现IComparable 接口,或者重写 Equal 方法,来实现自己的比较目的。因为对于引用类型,==号比较的是入口地址,对于同一个class 实现的两个objects来说,其入口地址显然不同。例如:判断List相等 L...
阅读全文
摘要:解析XML有很多方法,之前用专门写的XMLProcess 或XMLHelper 解析类。其实有个较简单的解析就是用Linq查询。例如有如下XML 2 DS6708-SR20007ZZR 1216300503088 4D6...
阅读全文
摘要:Task: 在Windows的Service里面定时的调用执行一个批处理文件。 private ApplicationOutput RunCommandOnPC(string executablePath, string args, string workingFolder, bool ...
阅读全文
摘要:创建文件夹:if (!Directory.Exists(@"C:\Program Files\TDTK\CoalTraffic\Image\WeightImage"))//判断文件夹是否已经存在 { Directory.CreateDirectory(@"C:\Program Files\TDTK\...
阅读全文