分享

C# 运行时发生System.InvalidOperationException错误

 gfdgd_xi 2021-03-21

在调试程序时,在以下句子出现错误

private void th()

        {

            Speech speech = new Speech();

            speech.Save("1.mp3",textBox1.Text, trackBar1.Value, trackBar2.Value);

        }

错误提示:

System.InvalidOperationException:“Cross-thread operation not valid: Control 'trackBar1’ accessed from a thread other than the thread it was created on.”

在这里插入图片描述

解决方法有两种:

1、在程序初始化模块

        public Form1()

        {

            InitializeComponent();

        }

输入以下语句:

CheckForIllegalCrossThreadCalls = false;

2、将出错语句放在下面代码的大括号里

this.BeginInvoke(new Action(delegate()

                {

                    

                }));

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多