班级孩子如何表现形式? [英] how do class child show to form?

查看:55
本文介绍了班级孩子如何表现形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

班级孩子如何表现形式?

这是我的班级

how do class child show to form?
this is My Class

public void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {

            string InputData = sp.ReadExisting();
           
            if (InputData != String.Empty)
            {
                goidulieu(InputData);
            }
        }
       
        public void goidulieu(string InputData)
        {
            Console.WriteLine("Tra loi: "+ InputData);
        }



Xem phim在线

推荐答案

显示类似这样的内容存在一些问题:主要是因为您在尝试显示数据一个SerialPort实例的DateRecieved事件 - 文档很清楚,事件不是从普通UI线程调用的 - 它是从一个完全不同的线程调用的,所以你不能直接访问表单控件 - 你必须调用它。

试试这个:

There are a couple of problems with displaying stuff like that: which are mostly concerned that you are trying to display data in a DateRecieved Event of a SerialPort instance - and the documentation is pretty clear that the event is not called from the "Normal" UI thread - it is called from a completely different thread, so you cannot access form controls directly - you have to invoke it.
Try this:
    if (InputData != "")
        {
        Invoke(new UpdateDisplayDelegate(ShowText), InputData);
        }
    }
private delegate void UpdateDisplayDelegate(string text);
private void ShowText(string s)
    {
    myTextBox.AppendText(s);
    }


这篇关于班级孩子如何表现形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆