
c#-多线程
c#-多线程
科学的发展-只不过是读大自然写的代码
科学的发展-只不过是读大自然写的代码
展开
-
线程更新UI方法总结
线程更新UI方法总结原创 2022-12-24 15:34:01 · 448 阅读 · 0 评论 -
c#-在指定的线程中调用函数
目的线程调用的切换,决定函数执行的线程,函数在哪个线程调用,就在哪个线程执行,那么如何让函数在指定的线程中执行呢?就是将函数放到消息队列中,然后在队列中运行函数,这样就实现了函数在指定的线程中调用代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespa.原创 2021-04-29 21:28:33 · 1992 阅读 · 0 评论 -
c# -给线程传递方法
概要给线程传递一个回调函数,需要先转换成委托。代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace 线程关系实验{ delegate void Funt(); class Program { stati.原创 2021-04-29 20:58:29 · 337 阅读 · 1 评论 -
c#-线程实验
线程实验目的:1.确认线程id和线程名称的差别2.线程调用父线程的函数在哪个线程中执行代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace 线程实验{ class Program { static voi原创 2021-04-29 14:34:22 · 177 阅读 · 0 评论 -
c#-线程-取消架构-Task-简单实验
1 概述cts = new CancellationTokenSource();cts.Token.Register(()=>Console.WriteLine(" task cancelled"));cts.Token.Register(()=>Console.WriteLine(" task cancelled"));CancellationToken token = cts.Token; if (token.IsCancellationReq...原创 2021-02-13 18:45:03 · 311 阅读 · 1 评论 -
c#-线程-取消架构-Parallel.For-简单实验
1.概要var cts = new CancellationTokenSource();cts.Token.Register(fun);CancellationToken = cts.Token2.代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Threading;u...原创 2021-02-13 16:44:06 · 194 阅读 · 1 评论 -
c#-多线程-任务-返回值-简单类型
概要var t1 = new Task<int>(Fun, a);int r = (int)t1.Result;static int Fun(Object o) { int a = (int)o; return a*2; }代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using ...原创 2021-02-13 15:39:12 · 277 阅读 · 0 评论 -
c#-异步回调-简单实验
1.概要要点public delegate int DelegateAdd(int a);IAsyncResult iar = da.BeginInvoke(6, goBack, da);static void goBack(IAsyncResult iar) {。。。。 DelegateAdd da = iar.AsyncState as DelegateAdd; int re = da.EndInvoke(iar...原创 2021-02-13 14:25:47 · 195 阅读 · 0 评论 -
c#-异步委托-简单实验
1 概要public delegate int DelegateAdd(int a);IAsyncResult iar = da.BeginInvoke(6, null, null);while (!iar.IsCompleted)int re = da.EndInvoke(iar);记忆要点:delegate,IAsyncResult,BeginInvoke,IsCompleted,IsCompleted2 代码using System;using System....原创 2021-02-13 14:12:24 · 120 阅读 · 0 评论 -
c#-线程-异步-await等待返回值
代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Threading;using System.Runtime.CompilerServices;namespace ConsoleApp7{ class Program { static void Ma.原创 2021-02-13 12:39:39 · 2958 阅读 · 0 评论 -
c#-线程-异步调用-TaskAwaiter-最简实践
代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Threading;using System.Runtime.CompilerServices;namespace ConsoleApp7{ class Program { static void Ma.原创 2021-02-13 12:33:15 · 1259 阅读 · 0 评论 -
c#-线程-task-async/await-简单应用
概述1.await可以等待事件的返回2.有等待的函数一定要加async代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Threading;namespace ConsoleApp7{ class Program { static void .原创 2021-02-13 11:20:14 · 170 阅读 · 0 评论 -
c#-线程同步-semaphore(信号量)-简单实验
代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Diagnostics;namespace ConsoleApp6{ class Program { static void Main(string[] args) { Cons原创 2021-02-13 09:34:12 · 409 阅读 · 0 评论 -
c#-线程同步-mutex(互斥锁)-互斥实验
代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace ConsoleApp5{ class Program { static void Main(string[] args) {原创 2021-02-12 22:16:50 · 197 阅读 · 2 评论 -
c#-线程同步-Mutex(互斥锁)-简单实验
概述bool mutexCreated;var mutex = new Mutex(false, "sigletonAppMutex", out mutexCreated);参数说明参数位置 参数 说明 1 false 2 sigletonAppMutex 设置互斥的名称 3 mutexCreated 该名称的互斥是否存在 特点1.可以跨进程,这是个系统级别的互斥。2.用于控制程序不能打开两次。3.当日也可以做..原创 2021-02-12 22:10:48 · 379 阅读 · 0 评论 -
c#-线程-Interlocked
代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace ConsoleApp5{ class Program { public static int num = 0; static void Main(st原创 2021-02-12 21:05:02 · 217 阅读 · 1 评论 -
c#-task-WaitAll
代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace ConsoleApp5{ class Program { public static int num = 0; static void Main(st原创 2021-02-12 20:01:35 · 281 阅读 · 0 评论 -
c#-线程-task-t2.Wait()
1.代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace ConsoleApp5{ class Program { public static int num = 0; static void Main.原创 2021-02-12 19:57:06 · 163 阅读 · 0 评论 -
c#-线程-Task.WhenAll
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace ConsoleApp5{ class Program { public static int num = 0; static void Main(string.原创 2021-02-12 19:51:42 · 380 阅读 · 0 评论 -
c#-线程-Task实验
1.代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace ConsoleApp5{ class Program { public static int num = 0; static void Main.原创 2021-02-12 19:41:16 · 106 阅读 · 0 评论 -
c#-Thread 线程状态知识
Thread函数函数名 运行进入的状态及其他说明 Thread.Start() :启动线程的执行; Thread.Suspend() :挂起线程,或者如果线程已挂起,则不起作用; Thread.Resume() :继续已挂起的线程; Thread.Interrupt() :中止处于Wait或者Sleep或者Join线程状态的线程; Thread.Join() :阻塞调用线程,直到某个线程终止时为止 Thread.Sleep() :将...原创 2021-02-12 12:40:04 · 397 阅读 · 0 评论 -
Thread.Suspend()已过时
关于Thread.Suspend()已过时的问题,我插到了下面的结果。1.结果实例函数Thread.Suspend和Thread.Resume在2.0版本下被标为obsolete.编译使用这2个函数的代码会得到使用System.Threading中的其他类,如Monitor,Mutex,Event,和Semaphore,以同步线程和保护资源。Thread.Suspend和Thread.Resume被废弃的主要原因是因为其使用很容易造成线程死锁(Deadlock)。要合理的管...原创 2021-02-12 12:26:38 · 1742 阅读 · 2 评论 -
c#-线程实验-用状态+非循环控制线程
说明// 这里暂停。那么什么时候回继续执行呢? myThread.Suspend(); //Thread.Sleep(1000 * 3 * 10); /* while (true) { if (fun1_end && fun2_end) { break; } }原创 2021-02-12 12:14:28 · 215 阅读 · 0 评论 -
c#-线程实验-用状态+循环控制线程
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace ConsoleApp4{ class Program { static int num=0; static bool fun1_end = false; static bool fun2_end ...原创 2021-02-12 11:01:32 · 312 阅读 · 0 评论 -
c#-线程-锁
1.概述线程锁英文名称 中文名称 概述 lock 锁 常用 InterLocked 自由锁 简单而特殊的情况 Monitor 监控 Enter~Exit(lock堆) SpinLock 自旋锁 Enter~Exit(lock栈) Mutex 互斥 名称 进程 这个的特点是继承与WaitHandle Semphore 信号量 ...原创 2020-09-05 20:50:45 · 488 阅读 · 0 评论 -
c# - parallel - 中断
using System;using System.Collections.Generic;using System.Text;using System.Linq;using System.Threading;using System.Threading.Tasks;// c# - parallel - 中断namespace ConsoleApp25{ class Pa...原创 2019-07-17 09:53:11 · 306 阅读 · 0 评论 -
c# - parallel - 中断
using System;using System.Collections.Generic;using System.Text;using System.Linq;using System.Threading;using System.Threading.Tasks;// c# - parallel - 中断namespace ConsoleApp25{ class Pa...原创 2019-07-17 09:31:23 · 424 阅读 · 0 评论 -
c#-Parallel-基础
代码using System;using System.Linq;using System.Threading;using System.Threading.Tasks;// c#-Parallel-基础namespace ConsoleApp25{ class Program { static int forNum = 5; sta...原创 2019-07-17 08:57:36 · 243 阅读 · 0 评论 -
c# - 异步编程-同步上下文
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Runtime.CompilerServices;using System.Threading;using System.Threading.Tasks;usin...原创 2019-07-16 15:13:46 · 714 阅读 · 0 评论 -
c#-异步编程基础-延续任务
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Runtime.CompilerServices;using System.Threading;using System.Threading.Tasks;// ...原创 2019-07-16 09:09:25 · 257 阅读 · 0 评论 -
c#-异步编程基础-使用Awaiter
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Runtime.CompilerServices;using System.Threading;using System.Threading.Tasks;// ...原创 2019-07-16 08:54:02 · 1745 阅读 · 0 评论 -
c#-异步编程基础-调用异步方法
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Runtime.CompilerServices;using System.Threading;using System.Threading.Tasks;// ...原创 2019-07-16 08:39:55 · 197 阅读 · 0 评论 -
c#-异步编程-异步编程基(15.3)
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;using System.Runtime.CompilerServices;using System.Threading;using System.Threading.Tasks;// c...原创 2019-07-11 16:44:11 · 174 阅读 · 0 评论 -
c#-异步编程-异步模式
c#-异步编程-异步模式using System;using System.IO;using System.Net;using System.Threading;namespace ConsoleApp19{ class Program { private const string url = "http://www.baidu.com"; ...原创 2019-07-11 14:46:16 · 335 阅读 · 0 评论 -
c#-异步编程-同步调用
c#-异步编程-同步调用using System;using System.IO;using System.Net;using System.Threading.Tasks;namespace ConsoleApp19{ class Program { private const string url = "http://www.baidu.com";...原创 2019-07-11 14:30:39 · 176 阅读 · 0 评论 -
c#-任务-返回值
c#-任务-返回值using System;using System.Threading.Tasks;using System.Threading;namespace ConsoleApp17{ class Program { static void Main(string[] args) { Console.Wr...原创 2019-07-11 14:19:08 · 234 阅读 · 0 评论 -
c#-任务-连续任务
c#-任务-连续任务using System;using System.Threading;using System.Threading.Tasks;// 连续任务namespace ConsoleApp18{ class Program { static void Main(string[] args) { C...原创 2019-07-11 13:57:28 · 388 阅读 · 0 评论 -
C#-多线程-任务-启动
C#-多线程-任务-启动方式using System;using System.Linq;using System.Threading;using System.Threading.Tasks;namespace ConsoleApp16{ class Program { static void Main(string[] args) ...原创 2019-07-11 09:36:05 · 266 阅读 · 0 评论 -
c#-线程池
c#-线程池using System;using System.Threading;namespace ConsoleApp15{ class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); ...原创 2019-07-10 14:21:54 · 332 阅读 · 0 评论 -
c#-线程-Thread
代码using System;using System.Threading;namespace ConsoleApp14{ public struct Data { public string Message; } class Program { static void Main(string[] args) ...原创 2019-07-10 13:56:40 · 181 阅读 · 0 评论