草庐IT

CLOSE_SYSTEM_DIALOGS

全部标签

C# 使用原生 System.IO.Compression 实现 zip 的压缩与解压

zip是一个非常常见的压缩包格式,本文主要用于说明如何使用代码文件或文件夹压缩为zip压缩包及其解压操作,我们采用的是微软官方的实现,所以也不需要安装第三方的组件包。使用的时候记得usingSystem.IO.Compression;//////将指定目录压缩为Zip文件//////文件夹地址D:/1////zip地址D:/1.zippublicstaticvoidCompressDirectoryZip(stringfolderPath,stringzipPath){DirectoryInfodirectoryInfo=new(zipPath);if(directoryInfo.Parent

C# 使用原生 System.IO.Compression 实现 zip 的压缩与解压

zip是一个非常常见的压缩包格式,本文主要用于说明如何使用代码文件或文件夹压缩为zip压缩包及其解压操作,我们采用的是微软官方的实现,所以也不需要安装第三方的组件包。使用的时候记得usingSystem.IO.Compression;//////将指定目录压缩为Zip文件//////文件夹地址D:/1////zip地址D:/1.zippublicstaticvoidCompressDirectoryZip(stringfolderPath,stringzipPath){DirectoryInfodirectoryInfo=new(zipPath);if(directoryInfo.Parent

C# 中针对 System.Runtime.InteropServices.ExternalException:“GDI+ 中发生一般性错误。”另一种图片保存方案

一般常用写Bimap保存会报错GDI+会报错的写法1publicvoidGetImageLocal()2{3intnum=9;4intinitWidth=256;5intinitHeight=256;67for(varc='\uff41';c'\uff5a';c++)8{9Bitmapimage=newBitmap(initWidth,initHeight);//初始化大小10Graphicsg=Graphics.FromImage(image);11g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;//设置图

C# 中针对 System.Runtime.InteropServices.ExternalException:“GDI+ 中发生一般性错误。”另一种图片保存方案

一般常用写Bimap保存会报错GDI+会报错的写法1publicvoidGetImageLocal()2{3intnum=9;4intinitWidth=256;5intinitHeight=256;67for(varc='\uff41';c'\uff5a';c++)8{9Bitmapimage=newBitmap(initWidth,initHeight);//初始化大小10Graphicsg=Graphics.FromImage(image);11g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;//设置图

sonar代码扫描bug:Use try-with-resources or close this "FileInputStream" in a "finally" clause.

  下面代码/***读取文件到byte数组**@paramtradeFile*@return*/publicstaticbyte[]file2byte(FiletradeFile){try{FileInputStreamfis=newFileInputStream(tradeFile);ByteArrayOutputStreambos=newByteArrayOutputStream();byte[]b=newbyte[1024];intn;while((n=fis.read(b))!=-1){bos.write(b,0,n);}fis.close();bos.close();byte[]bu

sonar代码扫描bug:Use try-with-resources or close this "FileInputStream" in a "finally" clause.

  下面代码/***读取文件到byte数组**@paramtradeFile*@return*/publicstaticbyte[]file2byte(FiletradeFile){try{FileInputStreamfis=newFileInputStream(tradeFile);ByteArrayOutputStreambos=newByteArrayOutputStream();byte[]b=newbyte[1024];intn;while((n=fis.read(b))!=-1){bos.write(b,0,n);}fis.close();bos.close();byte[]bu

【问题】为什么 System.Timers.Timer 更改间隔时间后的第一次触发时间是设定时间的三倍?

【问题】为什么System.Timers.Timer更改间隔时间后的第一次触发时间是设定时间的三倍?独立观察员2022年9月4日在编写“Wifi固定器 [1]”程序时,按如下方式使用了定时器://声明;privateTimer_Timer=newTimer(){Interval=1,AutoReset=true};//设置处理方法;_Timer.Elapsed+=newElapsedEventHandler(TimerHandler);//////定时器任务///privateasyncvoidTimerHandler(objectsource,ElapsedEventArgse){if(_T

【问题】为什么 System.Timers.Timer 更改间隔时间后的第一次触发时间是设定时间的三倍?

【问题】为什么System.Timers.Timer更改间隔时间后的第一次触发时间是设定时间的三倍?独立观察员2022年9月4日在编写“Wifi固定器 [1]”程序时,按如下方式使用了定时器://声明;privateTimer_Timer=newTimer(){Interval=1,AutoReset=true};//设置处理方法;_Timer.Elapsed+=newElapsedEventHandler(TimerHandler);//////定时器任务///privateasyncvoidTimerHandler(objectsource,ElapsedEventArgse){if(_T

dotnet 6 修复在 System.Text.Json 使用 source generation 源代码生成提示 SYSLIB1032 错误

在dotnet6内置了通过源代码生成的方式进行序列化JSON对象,性能非常高。使用的时候需要将Json序列化工具类换成dotnet运行时自带的System.Text.Json进行序列化,再加上一个继承JsonSerializerContext的辅助类型,且在此类型标记JsonSerializableAttribute特性,将此类型传入序列化和反序列化即可完成对接。然而在使用的过程中,如果发现此辅助类型的实际代码没有生成,且输出提示SYSLIB1032警告,那可能就是此辅助类型没有写对导致如官方文档的对SYSLIB1032的描述,这是由于标记了JsonSerializableAttribute的

dotnet 6 修复在 System.Text.Json 使用 source generation 源代码生成提示 SYSLIB1032 错误

在dotnet6内置了通过源代码生成的方式进行序列化JSON对象,性能非常高。使用的时候需要将Json序列化工具类换成dotnet运行时自带的System.Text.Json进行序列化,再加上一个继承JsonSerializerContext的辅助类型,且在此类型标记JsonSerializableAttribute特性,将此类型传入序列化和反序列化即可完成对接。然而在使用的过程中,如果发现此辅助类型的实际代码没有生成,且输出提示SYSLIB1032警告,那可能就是此辅助类型没有写对导致如官方文档的对SYSLIB1032的描述,这是由于标记了JsonSerializableAttribute的