随笔分类 -  dotNet Framework

Multiple Instance .NET Windows Service
摘要:It's not readily apparent how to install a Windows Service multiple times on a single machine. At first glance, it seems like it's not supported by th 阅读全文
posted @ 2018-01-17 10:19 今夜太冷 阅读(272) 评论(0) 推荐(0) 编辑
C# winForm webBrowser页面中js调用winForm类方法(转)
摘要:有时我们在winform项目中嵌入了网页,想通过html页面调用后台方法,如何实现呢?其实很简单,主要有三部: 1、在被调用方法类上加上[ComVisible(true)]标签,意思就是当前类可以com组件的形式供外包调用 2、在webBrowser控件中设置可被html页面调用的类即:webBrowser1.ObjectForScripting = this;前端即可通过win... 阅读全文
posted @ 2017-09-05 15:57 今夜太冷 阅读(1568) 评论(0) 推荐(0) 编辑
String escape/unescape into XML
摘要:Is there any C# function which could be used to escape and un-escape a string, which could be used to fill in the content of an XML element? And how to unescape? 【解决方案】 public static ... 阅读全文
posted @ 2017-02-21 11:26 今夜太冷 阅读(475) 评论(0) 推荐(0) 编辑
Intercepting a 404 in IIS 7 and up
摘要:Lately I've been working on a system that needs to serve flat files, which is what IIS is very good at. However, when a file does not exist (i.e. a 404 error occurs) there are several options: The f... 阅读全文
posted @ 2017-02-17 11:00 今夜太冷 阅读(190) 评论(0) 推荐(0) 编辑
Provider Pattern for Beginners in .net
摘要:Download ProviderPattern.zip Introduction Provider pattern allows the developers to create pluggable components. It was first introduced in framework 2.0 and it has lot of features like "Membershi... 阅读全文
posted @ 2017-01-25 11:41 今夜太冷 阅读(282) 评论(0) 推荐(0) 编辑
代码中AggregateException的处理
摘要:在async方法中,发生一个异常时,代码并不会直接跳到catch语句中去,而是继续执行,所以到最后catch语句中得到的错误信息是one or more exceptions occurs… 这样的设计给我们带来了麻烦就是传统的try/catch方法得到的无法得到具体的错误信息。 【解决方法】 在catch语句中记录错误信息 if (e is Ag... 阅读全文
posted @ 2016-12-07 16:56 今夜太冷 阅读(5666) 评论(0) 推荐(1) 编辑
C# windows form如何隐藏窗口?
摘要:you can use this line of code. It wont hide it, but it will be minimized: this.WindowState = FormWindowState.Minimized; in addition, if you don't want it showing on the task bar either, you ... 阅读全文
posted @ 2016-11-08 14:09 今夜太冷 阅读(2784) 评论(0) 推荐(0) 编辑
解决错误 Cannot await in the body of a catch clause
摘要:解决错误 Cannot await in the body of a catch clause static async Task f() { ExceptionDispatchInfo capturedException = null; try { await TaskThatFails(); } ... 阅读全文
posted @ 2016-11-03 13:40 今夜太冷 阅读(545) 评论(0) 推荐(0) 编辑
如何将Console application的Program函数变成支持async的?
摘要:如何将Console application的Program函数变成支持async的? class Program { static void Main(string[] args) { Task.Run(() => MainAsync()).Wait()... 阅读全文
posted @ 2016-10-28 16:13 今夜太冷 阅读(335) 评论(0) 推荐(0) 编辑
如何分隔两个base64字符串?
摘要:如何分隔两个base64字符串? 用逗号或者任意的不在base64字符串内的字符都可以。 All you have to do is to use a separator which is not a valid Basc64 character.Commais not a base64 character so you can use. Base64 characters are[... 阅读全文
posted @ 2016-10-09 13:44 今夜太冷 阅读(834) 评论(0) 推荐(0) 编辑
Nuget添加新项目的问题
摘要:为已有的几个项目添加了一个nuget package后,在解决方法中添加了一个新项目,然后想把这个nuget package添加到这个新建的项目中去,可以此时无法添加。 怎么办那? 【解决方法】 There's 3 approaches :).In NuGet 1.1 (The latest release) we've improved powershell pipelinin... 阅读全文
posted @ 2016-06-27 13:51 今夜太冷 阅读(3321) 评论(0) 推荐(0) 编辑
.net也疯狂:生成zip文件
摘要:平时我们创建Zip文件的时候,要么用现成的软件,要么用第三方的开源库。其实用.net自带的类操作起来也非常方便。以下用一个例子来展示:创建一个文件夹,里面可以包含任意的子目录。 创建一个控制台项目,添加一个类ZipManager,用来实现我们想要的操作。 为项目添加WindowsBase引用。(这个名字不太友好,但是与压缩相关的类就藏在里面) 在ZipManager.cs中添加对System.IO.Packaging命名空间的引用。 写一个构造函数,用来接收要执行压缩的文件路径。 创建一个方法ZipFolder,用来执行实际的压缩操作。在这个方法里面创建一个Pack... 阅读全文
posted @ 2012-08-07 20:32 今夜太冷 阅读(5508) 评论(18) 推荐(9) 编辑
应用Trace类实现对程序的跟踪
摘要:我们写完一个程序以后,如果在客户那里出现了问题,由于环境不同找起来很麻烦,比较好的一个方法就是在程序里面写上日志,这样如果出问题的话,直接查看日志就可以了。写日志当然有很多开源的东东,也可以自己来写。但是一是实现起来比较麻烦,二是需要一段时间来学习,三是可能会有潜在的问题。尤其是涉及到多线程的时候,潜在的问题就更多。其实.net已经提供了现成的类,使用起来非常方便。它就是System.Diagnostics.Trace. 这个类提供了很多方便的方法,比如Write, WriteLine等等。这个类还支持输出目标的设置,可以使用系统内置提供的Listener,也可以自己写Listener.我写了 阅读全文
posted @ 2012-06-15 17:00 今夜太冷 阅读(2141) 评论(2) 推荐(3) 编辑