随笔分类 -  c#

1 2 下一页

主线程create一个ConcurrentQueue ,然后用三个子线程往里面写数,主线程建timer检查ConcurrentQueue>某值,存数据库,存进多少就清ConcurrentQueue多少
摘要:代码 : 注:一开始用的是 List<> , 但发现 不能保证线程安全,后来在 stackoverflow 提问, 改用 ConcurrentQueue ,队列的特征是 front delete 的同时, 可以在 tail insert , 足以保证thread safe 原帖网址 : http:/ 阅读全文

posted @ 2017-05-11 15:14 齐文宣 阅读(206) 评论(0) 推荐(0)

c# 实现 ListBox 每一列可以有各自的颜色
摘要:上图是想实现的效果, 注意不是所有行一个颜色 首先把 listbox 的 DrawMode 属性 改为 OwnerDrawFixed 然后 override listbox 的 函数 DrawItem 系统重命名为 listBox1_DrawItem 阅读全文

posted @ 2017-05-05 17:51 齐文宣 阅读(5271) 评论(0) 推荐(0)

JSON序列化,并解码成为 datagridview 的 datasource
摘要:// encode List clientList = new List(); for (int i = 0; i source1 = JsonConvert.DeserializeObject>(sReply); var Dsource = new BindingSource(); ... 阅读全文

posted @ 2017-05-04 17:11 齐文宣 阅读(1638) 评论(0) 推荐(0)

c# winform 程序用126邮箱发邮件
摘要:代码如下: private void button1_Click(object sender, EventArgs e) { string strTitle = "alert! We have not receive new data from me... 阅读全文

posted @ 2015-03-31 10:09 齐文宣 阅读(989) 评论(0) 推荐(0)

c#客户端调用sql server 存储过程速度慢的问题
摘要:1 : c#代码是 SqlConnection connNew = null; connNew = new SqlConnection(@"Data Source="XXX"); ... 阅读全文

posted @ 2014-10-29 14:51 齐文宣 阅读(1004) 评论(0) 推荐(0)

c#转换 datetime
摘要:string formatString = "yyyyMMddHHmmss"; string s1 = "20140813200000"; DateTime EnrollDate = DateTime.ParseExact(s1, formatString, null); 阅读全文

posted @ 2014-08-14 14:25 齐文宣 阅读(407) 评论(0) 推荐(0)

c# 用代码定义带数据的datatable
摘要:DataTable customerTable = new DataTable(); customerTable.Columns.Add("clsCustomerID", typeof(string)); customerTable... 阅读全文

posted @ 2014-08-07 10:02 齐文宣 阅读(884) 评论(0) 推荐(0)

c# 将窗体从一个project复制到另一个project
摘要:步骤 1 : 假设窗体名为 Form1 ,将 Form1.design.cs , Form1.cs , Form1.resx 三个文件copy 到目标文件夹 2 : 先add existing ,将 Form1.design.cs添加进去 , 然后记得改 project namespace 3 ... 阅读全文

posted @ 2014-07-17 13:24 齐文宣 阅读(1096) 评论(0) 推荐(0)

自定义data table 的列类型,并填充数据
摘要:combobox 的 datasource一般是查询存储过程得到 ,但在测试或演示时,也可以自己定义 , 方法是 : DataTable customerTable = new DataTable(); customerTable.Columns.Add(... 阅读全文

posted @ 2014-05-24 13:56 齐文宣 阅读(2130) 评论(0) 推荐(0)

取某一个节点下的所有子节点
摘要:using System.Xml;using System.Xml.Linq;XmlDocument document = new XmlDocument();document.Load("SessionDef.xml");XmlNodeList nodelist = document.Select... 阅读全文

posted @ 2014-05-16 15:30 齐文宣 阅读(792) 评论(0) 推荐(0)

hash tabel 与 dictionary 的区别
摘要:1 :Hashtable 支持多个线程读,同时只有一个线程写 , dictionary 不支持 Hashtable supports multiple reader threads with a single writer thread, while Dictionary offers no thread safety. If you need thread safety with a generic dictionary, you must implement your own synchronization or (in .NET 4.0) use ConcurrentDictionary 阅读全文

posted @ 2014-02-18 10:31 齐文宣 阅读(356) 评论(1) 推荐(0)

dictionary 排序方法
摘要:假设有这样的乱序dictionary Dictionary d_Last10Mins_RQIM = new Dictionary(); d_Last10Mins_RQIM.Add("1", 10.0); d_Last10Mins_RQIM.Add("2", 20.0); d_Last10Mins_RQIM.Add("3", 30.0); d_Last10Mins_RQIM.Add("4", 90.0); d_Last10Mins_RQIM.Add("5", 11.... 阅读全文

posted @ 2014-02-11 15:37 齐文宣 阅读(7371) 评论(0) 推荐(0)

c#程序实现定时唤醒
摘要:要实现的功能是 :每隔10分钟启动程序, 启动后做一些消耗时间的操作,但不管这些操作需要多少时间(一般不会超过10分钟) ,程序仍然准时在10分钟后启动 。while (true){ int startTime = Environment.TickCount File.AppendAllText(strCurrentPath + @"\TimerLog.txt", "begin " + DateTime.Now.ToString() + "\r\n"); //do some work which will spent time spe 阅读全文

posted @ 2014-01-28 14:48 齐文宣 阅读(845) 评论(0) 推荐(0)

c# 编程实现发email , 用gmail邮箱
摘要:1 :加这两个 usingusing System.Net.Mail;using System.Net;2 : 发送人 和 收件人的设置 SmtpClient client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("myEmailAddress@gmail.com", "myPassword"), EnableSsl = true }; ... 阅读全文

posted @ 2014-01-09 16:14 齐文宣 阅读(1127) 评论(0) 推荐(0)

用 Table Valued Parameter 往 sql server 插数据
摘要:在维护以前的程序时,遇到这样的情况,需要向远程数据库写非常多的记录。原先的实现是这样的 :一 : 用datagridview显示要写入的记录,假设有10000条二:循环每一条记录,调用存储过程,将该条记录写入 ,代码如下 for (int i = 0; i @EnrollDate设 传进来的记录为 row意思是找出当前表中所有rateplanid 和row的@RatePlanID相同 ,且ExpiryDate大于row的@EnrollDate的记录然后update 这些记录的 expiryDate 然后再insert row-----------------------... 阅读全文

posted @ 2013-11-06 12:51 齐文宣 阅读(758) 评论(0) 推荐(0)

c#的windows service 怎么取当前exe的路径
摘要:windows service 不能用 directory.getcurrentdirectiry()取当前路径,正确的方法是 var location = System.Reflection.Assembly.GetEntryAssembly().Location; var directoryPath = Path.GetDirectoryName(location); 阅读全文

posted @ 2013-10-26 23:59 齐文宣 阅读(455) 评论(0) 推荐(0)

c#的windows service 为什么需要线程,老外的解释
摘要:The first time I wrote a service, I wondered whether we could do something like Listing 4, rather than go to the trouble of adding a timer. (注:我也是这么想的)Listing 4 The unstoppable service.protected override void OnStart(string[] args){ while (true) { // do some work // idle Thread.S... 阅读全文

posted @ 2013-10-26 21:58 齐文宣 阅读(720) 评论(0) 推荐(0)

关于 StreamReader 的 ReadToEnd() 方法
摘要:下面这段代码using (WebResponse response = request.GetResponse()){ using (StreamReader rd = new StreamReader(response.GetResponseStream())) { XDocument xd = XDocument.Load(rd.ReadToEnd()); }}在VS2005会报 :路径中有非法字符错误 如果改成using (WebResponse respons... 阅读全文

posted @ 2013-09-18 14:05 齐文宣 阅读(1930) 评论(0) 推荐(0)

sql server 导入 .net assembly 时, 报 assembly is built for an unsupported version of the Common Language Runtime. 错误的解决办法
摘要:一种是:让 sql server 2008 支持.net 4.0,但如何实现不知道简单方法是 : 用 vs 2005 build程序集或者在 project---->property---->application----->Target Framework 选 .net framework 3.5vs各版本使用的.net 版本分别是1.0: Visual Studio .NET1.1: Visual Studio .NET 20032.0: Visual Studio 2005 / 20083.0 / 3.5: Visual Studio 20084.0: Visual S 阅读全文

posted @ 2013-09-17 14:49 齐文宣 阅读(272) 评论(0) 推荐(0)

CLR has been unable to transition from COM context … for 60 seconds’ error. 此错误的解决方法
摘要:One fix for the problem is to go to the Debug -> Exceptions -> Managed Debug Assistants menu in Visual Studio and uncheck the ContextSwitchDeadlock来源网站 http://blog.wpfwonderland.com/2007/08/16/clr-has-been-unable-to-transition-from-com-context-for-60-seconds/ 阅读全文

posted @ 2013-09-10 10:48 齐文宣 阅读(657) 评论(0) 推荐(0)

1 2 下一页

导航