小编Gog*_*olo的帖子

跨线程操作无效

亲爱的,当我尝试调用排序方法时,我收到错误消息:

错误消息:跨线程操作无效:控制从创建它的线程以外的线程访问的"lbStart_Bubble".

这是什么做得不正确!?

Thread thBubble = new Thread(new ThreadStart(bubbleSort));
thBubble.Start();


public void bubbleSort()
    {
        int row = 0, column = 0;

        start = new TimeSpan(System.DateTime.Now.Ticks);
        lbStart_Bubble.Text = start.ToString();
        this.lbStart_Bubble.Refresh();

        for(row = 1; row <= list1.Length; row++)
        {
            for(column =0; column < list1.Length-1; column++)
            {

                Thread.Sleep(delay);
                tbResult_Bubble.Clear();
                for(int i=0; i<list1.Length; i++)
                    tbResult_Bubble.AppendText(list1[i] + " " );

                if(list1[column]>list1[column+1])
                    swap(list1[column], list1[column+1], column, column+1);
            }
            display(list1);
        }

        end = new TimeSpan(System.DateTime.Now.Ticks);
        lbEnd_Bubble.Text = end.ToString();

        lbTotal_Bubble.Text = end.Subtract(start).ToString();

        tbResult_Bubble.Clear();

        for(int i=0; i<list1.Length; i++)
            tbResult_Bubble.AppendText(list1[i] + …
Run Code Online (Sandbox Code Playgroud)

c# multithreading winforms

2
推荐指数
1
解决办法
1784
查看次数

在字符串中执行isnull

如何检查字符串是否为空并将其设置为某个值(如果是)?

就像在SQL中一样

isnull(string, 0)
Run Code Online (Sandbox Code Playgroud)

c# null

1
推荐指数
1
解决办法
220
查看次数

标签 统计

c# ×2

multithreading ×1

null ×1

winforms ×1