最近2年一直能看到 net core的介绍,看到支持wpf和winform引起了兴趣,写简单demo运行看效果和了解部署。

     现在准备把项目正式迁移到.net core, 就先用了一个比较单一的项目试试,编译很大部分很顺利通过,没有什么需要注意,

也就没有什么印象,一运行不得了各种报错。 也没有去看具体原因,先直接解决让程序运行正常。

 

一、begininvoke

 
   public static void dowork(action action, int millisecond = 500)
        {
            new action(() =>
            {
                system.threading.thread.sleep(millisecond);
                dispatcher.currentdispatcher.begininvoke(action);
            }).begininvoke(null, null);
        }

   以前的写法运行就报错,system.platformnotsupportedexception:“operation is not supported on this platform.”
   改后代码: 

 

 public static void dowork(action action, int millisecond = 500)
        {
            task.run(async () =>
            {
                await task.delay(millisecond);
                dispatcher.currentdispatcher.invoke(action);
            });
        }

     dispatcher.currentdispatcher.begininvoke(action);不会执行action,

   也需要改为:dispatcher.currentdispatcher.invoke(action);

 

二、system.windows.threading.dispatchertimer

         var valuetimer = new system.windows.threading.dispatchertimer();
            valuetimer.interval = new timespan(0, 0, 0, 0, 100);
            valuetimer.tick += (obj, e) =>
            {
                changerecognitionvalue(() => { valuetimer.stop(); });
            };
            valuetimer.start();

运行没有效果,直接改为下面:

         var valuetimer = new system.timers.timer(1 * 100);
            valuetimer.elapsed += (obj, e) =>
            {
                changerecognitionvalue(() => { valuetimer.stop(); });
            };
            valuetimer.start();

只是迁移一个控件,预览是否正常,瞬间不想去迁移。 因为.net5又出来了,到时候直接往上面迁移。

ps: 准备测试.net 5 第2个预览版 , 都准备好了 要求vs是16.6或者更新才可以,而我的是16.5.4,不支持…?