首页
归档
关于
友情链接
Search
1
clash for windows允许局域网连接,TAP和TUN模式
80,560 阅读
2
使用emby打造个人影视媒体库
16,462 阅读
3
解决kodi的emby插件无法找到文件...相对路径、绝对路径问题
9,680 阅读
4
Ubuntu to go/Linux to go/将linux系统安装到u盘或移动硬盘
6,769 阅读
5
魔改版rclone挂载世纪互联onedrive
4,696 阅读
技术
软件
文章
其他
登录
Search
标签搜索
sql
sqlserver
vps
onedrive
软件
代理
Oracle
magisk
onelist
世纪互联rclone
世界x流大学.com
transmission
Transmission Remote GUI
pt
ftp
emby插件
emby for kodi插件
qBittorrent
emby
nfo
旁逸斜出
累计撰写
33
篇文章
累计收到
85
条评论
首页
栏目
技术
软件
文章
其他
页面
归档
关于
友情链接
搜索到
16
篇与
技术
的结果
2022-11-28
C#AutoResetEvent和ManualResetEvent介绍
AutoResetEvent和ManualResetEvent是c#用来线程同步的。AutoResetEvent参考:https://learn.microsoft.com/zh-cn/dotnet/api/system.threading.autoresetevent?view=net-7.0Set():将事件设置为已发送信号状态,对于AutoResetEvent来说允许一个正在等待的线程继续执行。如果没有线程在等待,将保持无限期有信号状态。WaitOne():处于无信号状态时,阻塞当前线程直到接收到了信号量如果线程在处于信号状态时AutoResetEvent调用WaitOne,则线程不会阻塞。AutoResetEvent立即释放线程并返回到无信号状态。也就是说如果没有线程在WaitOne,先执行了Set,会导致后调用的第一次WaitOne失效不阻塞,第二次调用WaitOne阻塞会生效using System; using System.Threading; namespace AutoResetEvent_Examples { class MyMainClass { const int numIterations = 100; static AutoResetEvent myResetEvent = new AutoResetEvent(false); static int number; static void Main() { //定义线程并启动,MyReadThreadProc方法接收到信号量后读取当前线程的名字和number并打印 Thread myReaderThread = new Thread(new ThreadStart(MyReadThreadProc)); myReaderThread.Name = "ReaderThread"; myReaderThread.Start(); for(int i = 1; i <= numIterations; i++) { Console.WriteLine("Writer thread writing value: {0}", i); number = i; //Signal that a value has been written. //调用Set()后MyReadThreadProc()从WaitOne()继续执行 myResetEvent.Set(); //Give the Reader thread an opportunity to act. Thread.Sleep(1); } //Terminate the reader thread. myReaderThread.Abort(); } static void MyReadThreadProc() { while(true) { //The value will not be read until the writer has written // at least once since the last read. myResetEvent.WaitOne(); Console.WriteLine("{0} reading value: {1}", Thread.CurrentThread.Name, number); } } } }官网拷贝的代码,只有当Main()中的for循环调用myResetEvent.Set(),MyReadThreadProc()才会收到信号来读取当前线程的名字,否则就会一直停在myResetEvent.WaitOne()而不会继续向后执行。ManualResetEvent参考:https://learn.microsoft.com/zh-cn/dotnet/api/system.threading.manualresetevent?view=net-7.0Set():将事件设置为已发送信号状态,对于ManualResetEvent来说允许所有正在等待的线程继续执行Reset():设置事件无信号,使能够继续阻塞线程using System; using System.Threading; public class Example { // mre is used to block and release threads manually. It is // created in the unsignaled state. private static ManualResetEvent mre = new ManualResetEvent(false); static void Main() { Console.WriteLine("\nStart 3 named threads that block on a ManualResetEvent:\n"); //定义三个线程 for(int i = 0; i <= 2; i++) { Thread t = new Thread(ThreadProc); t.Name = "Thread_" + i; t.Start(); } Thread.Sleep(500); Console.WriteLine("\nWhen all three threads have started, press Enter to call Set()" + "\nto release all the threads.\n"); Console.ReadLine(); //给信号使ThreadProc()中的WaitOne()之后的代码执行 mre.Set(); Thread.Sleep(500); Console.WriteLine("\nWhen a ManualResetEvent is signaled, threads that call WaitOne()" + "\ndo not block. Press Enter to show this.\n"); Console.ReadLine(); for(int i = 3; i <= 4; i++) { Thread t = new Thread(ThreadProc); t.Name = "Thread_" + i; t.Start(); } //ManualResetEvent在调用Set()之后,WaitOne()并不会阻塞线程,要想阻塞线程,需要调用Reset()使没有信号,才能够继续阻塞线程 Thread.Sleep(500); Console.WriteLine("\nPress Enter to call Reset(), so that threads once again block" + "\nwhen they call WaitOne().\n"); Console.ReadLine(); //调用Reset()后继续阻塞线程 mre.Reset(); // Start a thread that waits on the ManualResetEvent. Thread t5 = new Thread(ThreadProc); t5.Name = "Thread_5"; t5.Start(); Thread.Sleep(500); Console.WriteLine("\nPress Enter to call Set() and conclude the demo."); Console.ReadLine(); mre.Set(); // If you run this example in Visual Studio, uncomment the following line: Console.ReadLine(); } private static void ThreadProc() { string name = Thread.CurrentThread.Name; Console.WriteLine(name + " starts and calls mre.WaitOne()"); mre.WaitOne(); Console.WriteLine(name + " ends."); } } /* Start 3 named threads that block on a ManualResetEvent: Thread_0 starts and calls mre.WaitOne() Thread_1 starts and calls mre.WaitOne() Thread_2 starts and calls mre.WaitOne() When all three threads have started, press Enter to call Set() to release all the threads. Thread_1 ends. Thread_0 ends. Thread_2 ends. When a ManualResetEvent is signaled, threads that call WaitOne() do not block. Press Enter to show this. Thread_3 starts and calls mre.WaitOne() Thread_3 ends. Thread_4 starts and calls mre.WaitOne() Thread_4 ends. Press Enter to call Reset(), so that threads once again block when they call WaitOne(). Thread_5 starts and calls mre.WaitOne() Press Enter to call Set() and conclude the demo. Thread_5 ends. */ 简单总结一下二者区别:1.AutoResetEvent调用Set只给一个正在WaitOne的线程信号使之继续执行,ManualResetEvent调用Set会给所有正在WaitOne的线程信号使之继续执行2.在调用Set后ManualResetEvent将保持有信号状态,WaitOne将失效,不再进行线程阻塞,需要重新阻塞的话要调用Reset,但AutoResetEvent(在已经有线程WaitOne的情况下)会自动返回到无信号状态。
2022年11月28日
116 阅读
0 评论
0 点赞
2021-12-26
Mssql数据库日期格式处理
基本格式系统时间 select GETDATE(); 格式转换字符串转日期select convert(datetime,'2021-02-27 15:52:15') --2021-02-27 15:52:15.000 select convert(datetime,'2021-02-27 15:52:15',20) --2021-02-27 15:52:15.000 select convert(datetime,'2021/02/27 15:52:15',111) --2021-02-27 15:52:15.000 select convert(datetime,'2020',20) --2020-01-01 00:00:00.000日期转字符串select CONVERT(VARCHAR(20),GETDATE(),120) --12 26 2021 6:47PM select CONVERT(VARCHAR(20),GETDATE()) --2021-12-26 18:47:46 select CONVERT(VARCHAR(32),GETDATE(),111) --2021/12/26CONVERT(data_type(length),data_to_be_converted,style)data_type(length) 规定目标数据类型(带有可选的长度)。data_to_be_converted 含有需要转换的值。style 规定日期/时间的输出格式。{collapse}{collapse-item label="style值对应的格式" open}参考:https://www.w3school.com.cn/sql/func_convert.asp Style ID Style 格式100 或者 0 mon dd yyyy hh:miAM (或者 PM)101 mm/dd/yy102 yy.mm.dd103 dd/mm/yy104 dd.mm.yy105 dd-mm-yy106 dd mon yy107 Mon dd, yy108 hh:mm:ss109 或者 9 mon dd yyyy hh:mi:ss:mmmAM(或者 PM)110 mm-dd-yy111 yy/mm/dd112 yymmdd113 或者 13 dd mon yyyy hh:mm:ss:mmm(24h)114 hh:mi:ss:mmm(24h)120 或者 20 yyyy-mm-dd hh:mi:ss(24h)121 或者 21 yyyy-mm-dd hh:mi:ss.mmm(24h)126 yyyy-mm-ddThh:mm:ss.mmm(没有空格)130 dd mon yyyy hh:mi:ss:mmmAM131 dd/mm/yy hh:mi:ss:mmmAM{/collapse-item}{/collapse}其他计算命令计算本年天数 select datediff(d,t.curr_year,dateadd(yy,1,t.curr_year)) from (select dateadd(d,-datepart(dy,getdate())+1,getdate()) curr_year) t select datediff(d,t.curr_year,dateadd(yy,1,t.curr_year)) from (select dateadd(d,-datepart(dy,convert(datetime,'2020',20))+1,convert(datetime,'2020',20)) curr_year) t 也可以用下面判断闰年的方法返回天数 DATEDIFF() 函数返回两个日期之间的时间 DATEADD() 函数在日期中添加或减去指定的时间间隔 DATEPART() 函数用于返回日期/时间的单独部分,比如年、月、日、小时、分钟等等判断闰年 select case when(YEAR(GETDATE())%4=0 and YEAR(GETDATE())%100<>0 or YEAR(GETDATE())%400=0) then '闰年' else '平年' end某月的第一天,最后一天 select dateadd(m, datediff(m,0,getdate()),0) select dateadd(day ,-1, dateadd(m, datediff(m,0,getdate())+1,0)) 附: Oracle日期转换
2021年12月26日
139 阅读
1 评论
0 点赞
2021-10-04
sqlsever代理启动失败
sqlserver代理启动失败日志提示:2021-08-31 16:23:22 - ? [100] Microsoft SQLServerAgent 版本 11.0.3000.0 (内部版本号 X64 unicode 零售): 进程 ID 3244 2021-08-31 16:23:22 - ? [495] SQL Server 代理启动服务帐户是 NT SERVICE\SQLSERVERAGENT。 2021-08-31 16:23:22 - ! [150] SQL Server 不接受连接(错误: 0)。请等待 SQL Server 允许连接。尝试的操作为: 启动时验证连接。 2021-08-31 16:23:22 - ! [000] 无法连接到服务器“(local)”;SQLServerAgent 无法启动 2021-08-31 16:23:22 - ! [298] SQLServer 错误: 27,注册表信息已损坏或丢失。请确保已正确安装和注册提供程序。 [SQLSTATE 08001] 2021-08-31 16:23:22 - ! [298] SQLServer 错误: 27,客户端无法建立连接 [SQLSTATE 08001] 2021-08-31 16:23:22 - ! [165] ODBC 错误: 0,与 SQL Server 建立连接时发生了与网络相关的或特定于实例的错误。找不到或无法访问服务器。请检查实例名称是否正确以及 SQL Server 是否配置为允许远程连接。有关详细信息,请参阅 SQL Server 联机丛书。 [SQLSTATE 08001] 2021-08-31 16:23:22 - ! [382] 无法登录到服务器“(local)”(DisableAgentXPs) 2021-08-31 16:23:22 - ? [098] SQLServerAgent 已终止(一般)解决方案:打开控制面板:找到2012 Native Client修复即可注:Express Edition是不支持sqlserver代理功能的(select @@VERSION可以查看版本)
2021年10月04日
164 阅读
0 评论
0 点赞
2021-08-17
Sqlserver中0和空字符串相等的问题
今天在SQL server中写存储过程时遇到一种0和空字符串相等的问题。场景:表A有value1(varchar)和value2(int)两个字段,现在插入一条新的数据(v1,v2),如果v1已存在,则给value2加上v2,若v1不存在则插入新的(v1,v2)(这个逻辑用merge into会更好些)开始我是这么写的declare @flag=int select @flag=value2 from A where A.value1=v1 if(@flag='') insert into ... else update A...但是这样是有问题的,当查询不到这条数据时,确实会插入,但是当value2=0的时候,这么写它依然会执行insert,也就是0='',可以通过下面的存储过程验证一下:CREATE PROCEDURE TEST AS BEGIN declare @a int declare @b varchar set @a=0 set @b=0 if(@a='') print('int a') if(@b='') print('varchar b') END GO然后执行会发现输出为 int a ,原因在于varchar和int是存在隐式转换的,导致转换之后0和空字符串变成了相等的。参考:https://www.cnblogs.com/liubaolongcool/archive/2011/08/24/2152552.html
2021年08月17日
135 阅读
0 评论
0 点赞
2021-04-25
excel技巧
excel拆分场景:excel现在有100万条数据,需要拆分成多张表。参考:https://www.cnblogs.com/jiujian/p/12642662.html1.在sheet页右击选择查看代码,或者按ALT+F11进入VBA命令界面,粘贴如下代码:拆分行数和路径自行设置,bt=1可以控制标题行数2.返回sheet页按ALT+F8,点击执行Sub cfb() Dim r, c, i, WJhangshu, WJshu, bt As Long r = Range("A" & Rows.Count).End(xlUp).Row c = Cells(1, Columns.Count).End(xlToLeft).Column bt = 1 'title WJhangshu = 250 '行数 WJshu = IIf(r - bt Mod 20000, Int((r - bt) / WJhangshu), Int((r - bt) / WJhangshu) + 1) For i = 0 To WJshu Workbooks.Add Application.DisplayAlerts = False ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & Format(i, String(Len(WJshu), 0)) & ".xlsx" '路径 Application.DisplayAlerts = True ThisWorkbook.ActiveSheet.Range("A1").Resize(bt, c).Copy ActiveSheet.Range("A1") ThisWorkbook.ActiveSheet.Range("A" & bt + i * WJhangshu + 1).Resize(WJhangshu, c).Copy _ ActiveSheet.Range("A" & bt + 1) ActiveWorkbook.Close True Next End Sub筛选重复或唯一数据开始--条件格式--突出显示单元格规则--重复值(其中也可以设置唯一值的显示规则),之后可以在条件格式的管理规则里面删除或定义更多规则筛选某列数据在另一列中不存在的参考:https://zhidao.baidu.com/question/2137999315270054628.html假设筛选A列有,B列没有的数据:在C1单元格输入公式=IF(COUNTIF(B:B,A1)>0,"B列有","B列没有"),回车,然后在C1单元格右下角,出现“+”后,双击或下拉即可。
2021年04月25日
339 阅读
2 评论
0 点赞
1
2
...
4