摘要:socket或tcpclient, 发送或接受时, 采用子线程发送接受数据. 主线程可以new 一个ManualResetEvent(成员变量, 子线程, 主线都可以访问), 使用WaitOne方法, 使主线程暂停. 在子线程网络执行成功, 或达到一定时间后调用ManualResetEvent 的Set方法使主线程继续执行.参考:C# Socket连接请求超时机制
阅读全文
摘要:///<summary>///把四个字符长度的Unicode转成对应的汉字///</summary>///<paramname="str">长度是4的Unicode</param>///<returns>对应的汉字,若转换出错则返回原字符串</returns>privatestringUnicode2UnitCharacter(stringstr){if(str.Length!=4){returnstr;}try{bytecode=System.Convert.ToByte(str.Substring(
阅读全文
摘要:System.Configuration.ConfigurationSettings.AppSettings["Key"];但是现在FrameWork2.0已经明确表示此属性已经过时。并建议改为ConfigurationManager或WebConfigurationManager。并且AppSettings属性是只读的,并不支持修改属性值.但是要想调用ConfigurationManager必须要先在工程里添加system.configuration.dll程序集的引用。(在解决方案管理器中右键点击工程名称,在右键菜单中选择添加引用,.net TablePage下即可找到
阅读全文
摘要:MessageBox.Show("Environment.CurrentDirectory:"+Environment.CurrentDirectory+"\r\nApplication.ExecutablePath"+Application.ExecutablePath+"\r\nDirectory.GetCurrentDirectory()"+Directory.GetCurrentDirectory()+"\r\nAppDomain.CurrentDomain.BaseDirectory"+AppDomain
阅读全文
摘要:更新程序是比较本地与局域网另一台机上的UpdateList.xml文件中Version差异来更新的.如果Version不一样,会调用更新更新程序检查Files下面各个File的ver如果本地与远程不一样, 或没有则会更新本地的文件.在主程序开始时调一CheckUpdate 一时内打开多次只会提示一次private static void CheckUpdate(){ try { XmlDocument docLocal = new XmlDocument(); XmlDocument docServer = new XmlDocument(); docLocal.Load...
阅读全文
摘要://右击项目->属性->应用程序->程序集信息可以设置版本号//程序集版本stringver=System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();Console.WriteLine("程序集版本:"+ver);//文件版本System.Diagnostics.FileVersionInfomyFileVersionInfo=System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Diagnost
阅读全文
摘要:msn传送exe rar等文件要杀毒软件检测. 自己写个软件修改注册表, 跳过检测usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingMicrosoft.Win32;usingSystem.Runtime.InteropServices;namespaceRegiterMsnAnitVirus{classProgram{staticvoidMain(string[]args){//打开注册表修改msn杀毒软件键值RegistryKeykey=Registry.Users.OpenS
阅读全文
摘要:///<summary>///根据图片路径,返回一张灰度图///</summary>///<paramname="strPicPath">图片路径</param>///<returns>灰度图对象</returns>publicImageGetGrayPicture(stringstrPicPath){/**Stride:图像扫描宽度*图像在内存里是按行存储的。扫描行宽度就是存储一行像素,用了多少字节的内存。*比如一个101×200大小的图像,每个像素是32位的(也就是每个像素4个字节),那么
阅读全文
摘要:///<summary>///返回一个16位hash码(先将图片转成灰度,再分块得到每个分块的灰度值(0-255),再开方,得0-15值.正好用16进制数表示///</summary>///<paramname="strPicPath">图片路径</param>///<returns>16位hash码</returns>publicstringGetPictureHashCode(stringstrPicPath){try{//如果传的是字节数组可以用MemoryStream来读取intiHBlockN
阅读全文
摘要:使用了自定义控件(TextBox里面放了一个按钮)TreeView例子延迟加载树, 点击节点时只读树的两层可添加 删除 修改节点例子下载
阅读全文
摘要:C#如果访问网页可以用HttpWebRequest, HttpWebResponse两个类.这儿是用Socket得获取网页的一个例子, 支持301 302跳转. 以及gzip网页解压, 自动切换编码. publicclassGetPageWithSocket{///<summary>///使用socket得到网页html///</summary>///<paramname="strUrl">网页url</param>///<returns>网页html代码</returns>publicstringGe
阅读全文
摘要:下载图片 有时网络卡, 图片只有半张, 用这个IsCompletedImage可以检查下载的图片是否完整, 可以检查jpg, bmp, gif, png.主要根据图片开头和结尾的特定字节来判断的.staticvoidMain(string[]args){ stringstrFileName=@"c:\test.jpg";if(IsCompletedImage(strFileName)) { Console.WriteLine("完整图片"); }else Console.WriteLine("残缺图片"); Console.ReadK
阅读全文
摘要:usingSystem.Runtime.InteropServices;namespaceConsoleTest{classProgram{publicenumShowCommands:int{SW_HIDE=0,SW_SHOWNORMAL=1,SW_NORMAL=1,SW_SHOWMINIMIZED=2,SW_SHOWMAXIMIZED=3,SW_MAXIMIZE=3,SW_SHOWNOACTIVATE=4,SW_SHOW=5,SW_MINIMIZE=6,SW_SHOWMINNOACTIVE=7,SW_SHOWNA=8,SW_RESTORE=9,SW_SHOWDEFAULT=10,SW_FO
阅读全文
摘要:http://www.accdb.net/article.asp?id=608http://hi.baidu.com/yeihizhi1/blog/item/455c07d42fcf2ace50da4b31.htmlhttp://www.csharpwin.com/csharpspace/8382r3615.shtmlhttp://developer.51cto.com/art/200909/149097.htmhttp://www.cnntec.com/archiver/showtopic-2973.htmlhttp://iofeng.com/Ublog/ShowBlog.aspx?id=2
阅读全文
摘要:int[, ,] array = new int[5, 2, 3]; //定义一个5 * 2 * 3 =30的三维数组(array.Length=30) 多维数组只算一个数组 array[1, 1, 1] = 3; array[1, 1, 2] = 4;。。。array[5, 2, 2] = 8;arrayy[5, 2, 3] = 9;===========数组的数组包括多维数组int[][][] array2 = new int[4][][];//数组的数组int[][] array = new int[][]{new int[]{1,2,4},new int[]{1,2,3...
阅读全文
摘要:int? 是System.Nullable<int> 的简写System.Nullable<T> 是泛型 可以有string? float?int 不可以传null值 但int? 可以传null值int? temp = null;int temp2 = temp ?? -1;int?其实是个结构体int? 值不能赋值给int, 但可以如上写法?? 是表示前面值为空则传后面的值.值类型弄保存在栈中包括结构,原始类型,枚举
阅读全文
摘要:提取http://www.codefans.net/jscss/code/1866.shtm等l类似网页中运行区块的html代码 并保存到本地.应该是将 源码爱好者 » 网页特效代码 下面的子目录都抓下来了, 我机器上运行了15min抓了有10几个子目录 共4M多用到了正则表达式,文件读取保存, 多线程是用vs2005写的, winformform1.cs 代码Code highligh...
阅读全文