摘要:代码 : 注:一开始用的是 List<> , 但发现 不能保证线程安全,后来在 stackoverflow 提问, 改用 ConcurrentQueue ,队列的特征是 front delete 的同时, 可以在 tail insert , 足以保证thread safe 原帖网址 : http:/
阅读全文
摘要:上图是想实现的效果, 注意不是所有行一个颜色 首先把 listbox 的 DrawMode 属性 改为 OwnerDrawFixed 然后 override listbox 的 函数 DrawItem 系统重命名为 listBox1_DrawItem
阅读全文
摘要:// encode List clientList = new List(); for (int i = 0; i source1 = JsonConvert.DeserializeObject>(sReply); var Dsource = new BindingSource(); ...
阅读全文
摘要:代码如下: private void button1_Click(object sender, EventArgs e) { string strTitle = "alert! We have not receive new data from me...
阅读全文
摘要:1 : c#代码是 SqlConnection connNew = null; connNew = new SqlConnection(@"Data Source="XXX"); ...
阅读全文
摘要:string formatString = "yyyyMMddHHmmss"; string s1 = "20140813200000"; DateTime EnrollDate = DateTime.ParseExact(s1, formatString, null);
阅读全文
摘要:DataTable customerTable = new DataTable(); customerTable.Columns.Add("clsCustomerID", typeof(string)); customerTable...
阅读全文
摘要:步骤 1 : 假设窗体名为 Form1 ,将 Form1.design.cs , Form1.cs , Form1.resx 三个文件copy 到目标文件夹 2 : 先add existing ,将 Form1.design.cs添加进去 , 然后记得改 project namespace 3 ...
阅读全文
摘要:combobox 的 datasource一般是查询存储过程得到 ,但在测试或演示时,也可以自己定义 , 方法是 : DataTable customerTable = new DataTable(); customerTable.Columns.Add(...
阅读全文
摘要:using System.Xml;using System.Xml.Linq;XmlDocument document = new XmlDocument();document.Load("SessionDef.xml");XmlNodeList nodelist = document.Select...
阅读全文
摘要: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
阅读全文
摘要:假设有这样的乱序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....
阅读全文
摘要:要实现的功能是 :每隔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
阅读全文
摘要: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 }; ...
阅读全文
摘要:在维护以前的程序时,遇到这样的情况,需要向远程数据库写非常多的记录。原先的实现是这样的 :一 : 用datagridview显示要写入的记录,假设有10000条二:循环每一条记录,调用存储过程,将该条记录写入 ,代码如下 for (int i = 0; i @EnrollDate设 传进来的记录为 row意思是找出当前表中所有rateplanid 和row的@RatePlanID相同 ,且ExpiryDate大于row的@EnrollDate的记录然后update 这些记录的 expiryDate 然后再insert row-----------------------...
阅读全文
摘要:windows service 不能用 directory.getcurrentdirectiry()取当前路径,正确的方法是 var location = System.Reflection.Assembly.GetEntryAssembly().Location; var directoryPath = Path.GetDirectoryName(location);
阅读全文
摘要: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...
阅读全文
摘要:下面这段代码using (WebResponse response = request.GetResponse()){ using (StreamReader rd = new StreamReader(response.GetResponseStream())) { XDocument xd = XDocument.Load(rd.ReadToEnd()); }}在VS2005会报 :路径中有非法字符错误 如果改成using (WebResponse respons...
阅读全文
摘要:一种是:让 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
阅读全文
摘要: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/
阅读全文