C#
漫步的社会人
继续前行
展开
-
C#开启线程,有参数线程,无参数线程
//创建线程Thread AcceptSocketThread = new Thread(new ParameterizedThreadStart(StartListen));AcceptSocketThread.IsBackground = true;AcceptSocketThread.Start(socketWatch); private void StartCADListen(object obj){ Socket socketWatch = obj as Socket;}.原创 2021-04-20 15:33:31 · 335 阅读 · 0 评论 -
C#动态加载dll
/// <summary> /// 动态加载DLL,C#.net框架的dll /// </summary> /// <param name="lpFileName">DLL路径</param> /// <param name="Namespace">命名空间</param> /// <param name="ClassName">类名</.原创 2021-04-20 15:19:51 · 1564 阅读 · 0 评论 -
C#动态调用COM组件
//调用 com名称 方法 参数InvokeMethod("ScriptEngine.Script", "Run", new object[] { script }); public class COMInfo { public object Instance; public Type COMType; public COMInfo(Type type, object instance) .原创 2021-04-20 15:17:52 · 1256 阅读 · 0 评论 -
C#使用iTextSharp给PDF文件添加水印,PDF文件加密,PDF文件旋转
//添加水印public void AddWaterMark(string filePath, string text) { iTextSharp.text.pdf.PdfReader pdfReader = null; iTextSharp.text.pdf.PdfStamper pdfStamper = null; string tempPath = Path.GetDirectoryName(fileP...原创 2021-04-19 16:43:42 · 1668 阅读 · 0 评论 -
Unable to load DLL ‘**.dll‘: 找不到指定的模块。 (Exception from HRESULT: 0x8007007E)
在项目中使用C#代码调用C++ DLL时。常常会出现这个问题:在开发者自己的电脑上运行没有问题,但是部署到客户电脑上时会出现下面问题:Unhandled Exception:System.DllNotFoundException: Unable to load DLL"**":找不到指定的模块。 出现这个问题的原因:一般是该客户电脑上缺少该DLL的依赖项,需要使用Dependency Walker查看。http://www.dependencywalker.com/下载后在客户电脑上查看依.原创 2020-07-13 17:42:57 · 6960 阅读 · 0 评论 -
C#中byte数组转换为int,int转换为byte数组
//2位byte转为int private int Byte2Int(byte[] b) { return ((b[0] & 0xff) << 8) | (b[1] & 0xff); } //3位byte转为int private int Byte3Int(by...原创 2020-01-17 15:59:01 · 5033 阅读 · 0 评论 -
C# CRC16校验算法
/// CRC16 private byte[] CRC16(byte[] data) { int len = data.Length; if (len > 0) { ushort crc = 0xFFFF; ...原创 2020-01-17 15:57:22 · 3248 阅读 · 0 评论 -
C#16进制字符串转为byte数组,byte数组转换为16进制字符串
/// 16进制字符转换为字节 private byte[] HexStringToByte(string hs) { string strTemp = ""; byte[] b = new byte[hs.Length / 2]; for (int i = 0; i < hs.Leng...原创 2020-01-17 15:54:29 · 4145 阅读 · 0 评论 -
C#中16进制直接转换为bcd码,即16进制数为10进制数
//16进制转为bcd public string HexToBcd(Byte AData) { try { StringBuilder sb = new StringBuilder(1* 2); sb.Append(AData >> 4);...原创 2020-01-17 15:51:43 · 1552 阅读 · 0 评论 -
C#实现函数的超时退出功能
private static void Main(string[] args) { Console.WriteLine("Begin:" + DateTime.Now); bool ret = Process(string.Empty, 10000); Console.WriteLine("Re...转载 2020-01-17 15:45:42 · 684 阅读 · 0 评论 -
C#程序在一个终端中只允许打开一次,防止多次打开
/// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application....原创 2020-01-17 15:37:07 · 337 阅读 · 0 评论 -
C#WinForm - 最小化或关闭时隐藏到系统托盘
STEP1、添加托盘图标控件NotifyIcon(直接从工具箱中拖动添加即可)STEP2、添加(重写)窗口尺寸变动函数Form1_Resize private void Form1_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowStat...转载 2020-01-17 15:33:41 · 813 阅读 · 0 评论 -
判断Socket是否断开
/// <summary> /// 接收数据 /// </summary> private void OnReceive(object ob) { var key = ClientSocket.LocalEndPoint as IPEndPoint; ...原创 2020-01-17 10:18:11 · 435 阅读 · 0 评论 -
C#显示不同颜色的文本到textbox
class Information { public static RichTextBox txt_log; public delegate void LogAppendDelegate(Color color, string text); /// <summary> /// 追加显示文本 ...转载 2019-11-21 14:08:30 · 3450 阅读 · 0 评论 -
C#封装mysql类,连接数据库,执行数据库语句
class MysqlClass { private MySqlConnection SqlConn; public MysqlClass(string ServerIp,string Port, string SQLUserName, string SQLUserPass, string DataBase) { t...原创 2019-11-21 14:05:28 · 325 阅读 · 1 评论 -
C#获取本地IP和外网IP
//外网IPpublic static string GetIP() { using (var webClient = new WebClient()) { try{ webClient.Credentials = CredentialCache.Default...原创 2019-11-21 14:02:25 · 316 阅读 · 0 评论 -
C#解析、拼接json字符串
//组成json字符串 JObject ret = new JObject(); ret["xxx"] = "1"; JArray body = new JArray(); JObject obj = new JObject(); obj["aaa"] = "2"; ...原创 2019-11-20 16:31:16 · 1216 阅读 · 0 评论 -
C#使用FileStream读写文件
#region 使用FileStream读取数据 using (FileStream fsRead = new FileStream(@"C:\Users\Administrator\Desktop\2.txt", FileMode.OpenOrCreate, FileAccess.Read)) { ...原创 2019-08-18 09:26:42 · 1041 阅读 · 0 评论 -
C#委托,实现窗口传值
Form1:private void button1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); //将UpdateText这个方法作为参数 传递给委托变量 frm2.wt = UpdateText; f...原创 2019-08-15 13:55:42 · 153 阅读 · 0 评论 -
该字符串未被识别为有效的DateTime处理
转化的字符串不是正常的日期格式,导致输出异常private string Date(string a) { DateTime dtDate; if (DateTime.TryParse(a, out dtDate)) { return DateTime.Parse((a)....原创 2018-08-26 09:24:03 · 5637 阅读 · 0 评论 -
C#线程访问UI控件时出现假死
private delegate void InvokeHandler(); public Form1() { InitializeComponent(); Control.CheckForIllegalCrossThreadCalls = false; ...原创 2019-06-22 15:35:19 · 343 阅读 · 0 评论