代码改变世界

随笔分类 -  C#

EF There is already an open DataReader associated with this Command

2017-09-05 16:00 by Dorisoy, 1536 阅读, 收藏,
摘要: 捕捉到 System.InvalidOperationException _HResult=-2146233079 _message=意外的连接状态。在使用包装提供程序时,请确保在已包装的 DbConnection 上实现 StateChange 事件。 HResult=-2146233079 解决 阅读全文

MVC5 您不能调用控制器“xx”上的操作方法“xx”,因为该方法是一种泛型方法

2017-07-13 08:56 by Dorisoy, 1165 阅读, 收藏,
摘要: 在 MVC5 中当使用 routes.MapMvcAttributeRoutes() 添加路由属性是导致在控制器创建的泛型方法调用错误: Cannot call action method 'System.Collections.Generic.IEnumerable1[System.Web.Mvc 阅读全文

Geckofx 45 正确模拟键盘输入的事件绑定方法

2017-04-26 14:10 by Dorisoy, 1797 阅读, 收藏,
摘要: var inputs = selection.GetElementsByTagName("input").Select(p => p as Gecko.DOM.GeckoInputElement).Where(p => p.GetAttribute("placeholder") == "Stake"); foreach (var inp... 阅读全文

实现多线程异步自动上传本地文件到 Amazon S3

2017-03-01 13:47 by Dorisoy, 2746 阅读, 收藏,
摘要: 最近抽空做个小工具,使用AWSSDK 对本地文件目录监控,并自动同步上传文件到S3 的过程,使用的是多线程异步上传,针对大文件进行了分块 参考文献: https://www.codeproject.com/Articles/131678/Amazon-S-Sync https://aws.amazo 阅读全文

ASP.Net 重写IHttpModule 来拦截 HttpApplication 实现HTML资源压缩和空白过滤

2016-09-24 21:26 by Dorisoy, 1353 阅读, 收藏,
摘要: 务实直接上代码: 1. 重写FilterModule.cs 2. 处理压缩和匹配自定义过滤 CompressWhitespaceFilter.cs 在这里需要注意的是对GZIP 的释放,否则流数据会读取不到: 对于C#非托管资源释放(Finalize/Dispose)方法理解: http://www 阅读全文

Code-Based Configuration (EF6 onwards)

2016-06-01 09:55 by Dorisoy, 249 阅读, 收藏,
摘要: https://msdn.microsoft.com/en-us/data/jj680699#Using 阅读全文

SQLite Code配置DbConfiguration

2016-06-01 09:54 by Dorisoy, 1297 阅读, 收藏,
摘要: [DbConfigurationType(typeof(SQLiteConfiguration))] public partial class rsapiEntities : DbContext { public rsapiEntities() : base("name=rsapiEntities") { ... 阅读全文

C#里System.Data.SQLite中对GUID的处理

2016-05-31 10:03 by Dorisoy, 1299 阅读, 收藏,
摘要: string sqlstring = "select * from endpoint_policy where HEX([UserGuid]) ='" + CommonHelper.ConvertGuid(uguid) + "'"; var query = db.Database.SqlQuery(sqlstring).AsQueryable(); var endpoint_policy ... 阅读全文

c#并行任务多种优化方案分享(异步委托)

2016-05-01 12:42 by Dorisoy, 730 阅读, 收藏,
摘要: 遇到一个多线程任务优化的问题,现在解决了,分享如下。 假设有四个任务: 任务1:登陆验证(CheckUser) 任务2:验证成功后从Web服务获取数据(GetDataFromWeb) 任务3:验证成功后从数据库获取数据(GetDatFromDb) 任务4:使用2、3的数据执行一个方法 (StartP 阅读全文

调用API 清屏

2016-04-22 15:10 by Dorisoy, 489 阅读, 收藏,
摘要: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; namespace calculate { struct StdHandleEn... 阅读全文

C#Process执行批处理后如何获取返回值?

2016-04-22 15:09 by Dorisoy, 8196 阅读, 收藏,
摘要: 代码如下 p.StartInfo = new System.Diagnostics.ProcessStartInfo(path, pwd); p.Start();其中path是个BAT的路径!我想要得到执行后的返回值来判断批处理运行期间是否错误?请问如何做呢?批处理程序内容如下:@echo offf 阅读全文

AutoFac使用方法总结:Part III

2016-04-21 09:58 by Dorisoy, 236 阅读, 收藏,
摘要: 生命周期 AutoFac中的生命周期概念非常重要,AutoFac也提供了强大的生命周期管理的能力。 AutoFac定义了三种生命周期: Per Dependency为默认的生命周期,也被称为’transient’或’factory’,其实就是每次请求都创建一个新的对象 [Fact] public v 阅读全文

AutoFac使用方法总结:Part II

2016-04-21 09:56 by Dorisoy, 271 阅读, 收藏,
摘要: 事件 AutoFac支持三种事件:OnActivating,OnActivated,OnRelease。OnActivating在注册组件使用之前会被调用,此时可以替换实现类或者进行一些其他的初始化工作,OnActivated在实例化之后会被调用,OnRelease在组件释放之后会被调用。 publ 阅读全文

AutoFac使用方法总结:Part I

2016-04-21 09:54 by Dorisoy, 289 阅读, 收藏,
摘要: 注册部分 使用RegisterType进行注册 [Fact] public void can_resolve_myclass() { var builder = new ContainerBuilder(); builder.RegisterType<MyClass>(); IContainer c 阅读全文

FileStream:The process cannot access the file because it is being used by another process

2016-04-05 09:38 by Dorisoy, 1039 阅读, 收藏,
摘要: 先看下面一段代码(先以共享的方式打开文件读写,然后以只读的方式打开相同文件): FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); FileStream 阅读全文

C# The process cannot access the file because it is being used by another process

2016-04-05 09:32 by Dorisoy, 3161 阅读, 收藏,
摘要: C# The process cannot access the file because it is being used by another process The process cannot access the file because it is being used by anoth 阅读全文

在C#环境中动态调用IronPython脚本(二)

2016-04-03 11:56 by Dorisoy, 993 阅读, 收藏,
摘要: 一、Python数据类型与C#数据类型的对应 Python中数据类型中的简单类型,例如int,float,string可以对应到C#环境中的int32,double,string,这些对应比较直观,Python中的复杂数据类型,例如List,Set等是C#环境中没有的,好在IronPython提供了 阅读全文

asp.net访问网络路径方法(模拟用户登录)

2016-01-13 13:14 by Dorisoy, 482 阅读, 收藏,
摘要: public class IdentityScope : IDisposable{ // obtains user token [DllImport("advapi32.dll", SetLastError = true)] static extern bool LogonUser... 阅读全文

C# List使用District去重复数据

2016-01-13 13:13 by Dorisoy, 806 阅读, 收藏,
摘要: class ListDistinctDemo { static void Main(string[] args) { List personList = new List(){ new Person(3),//重复... 阅读全文

CallContext和多线程

2015-06-14 20:48 by Dorisoy, 358 阅读, 收藏,
摘要: 前一段时间正好要在某个网页程序上开一个多线程调用多个组件的尝试,这些组件是有其他团队开发的(如:印度/俄罗斯),所以修改它们的代码看起来是不太现实的,但是,令人恼火的是他们的代码中大量的用到了AppContext.Current这个对象(实际上是用了HttpContext.Current.Item来... 阅读全文