更新记录 本文迁移自Panda666原博客,原发布时间:2021年7月2日. 在同步代码块中调用异步方法,方法有很多. 一.对于有返回值的Task 在同步代码块中直接访问 Task 的 Result 属性,这会阻塞调用线程直到返回Result为止. 代码实例: using System; using System.Threading; using System.Threading.Tasks; namespace PandaTestClass { class Program { private
1.同步方法 package Synchronized; /************************************同步方法****************************************/ public class PrintTest { public static void main(String[] args) { Print p = new Print(); Thread t1 = new PrintNumber(p); Thread t2 = new P