Hi Stack Overflow community,
I would like to append data from another thread to my richtextbox. I have written following code for this. It reads dongle information.
namespace MAXREFDES104 {
public partial class Form1 : Form
{
    IBleDongle dongle;
    List<ulong> bleAddresses = new List<ulong>();
    string comPort = "com4";
    public Form1()
    {
        InitializeComponent();
        Run(comPort);
    }
    public void Run(string comPort)
    {
        richTextBox1.AppendText("Connecting to dongle on " + comPort + "\n");
        dongle = new CySmartBleDongle(comPort);
        if (!dongle.Connect())
        {
            richTextBox1.AppendText("Error: Unable to connect to dongle at " + comPort + "\n");
            return;
        }
        richTextBox1.AppendText("Scanning for BLE Devices\n");
        bleAddresses.Clear();
        dongle.DeviceFound += OnDongleDeviceFound;
        dongle.StartScan();
    }
    private void OnDongleDeviceFound(object sender, BleDeviceEventArgs e)
    {
        if (e.Name.StartsWith("MAXREFDES104") && !bleAddresses.Contains(e.Address))
        {
            string txt = ("[" + bleAddresses.Count + "] " + e.Address.ToString("X02") + " Type: " + e.AddressType
                + " Power: " + e.Rssi + " Name: " + e.Name);
            SetText(txt.ToString());
            bleAddresses.Add(e.Address);
        }
    }
    public void SetText(string text)
    {
        if (InvokeRequired)
        {
            this.BeginInvoke(new Action<string>(SetText), new object[] { text });
            return;
        }
        this.richTextBox1.Text += text;
    }
}
}
The issue is it reads device on every other time e.g. it finds device as shown below:
then it could not:
Would it be possible to offer some comments on this one?


