© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
14 replies
SneakySquid

❔ crashing

Any idea how to prevent this code from crashing unity?
    SerialPort sp = new SerialPort("COM3", 9600);
sp.Open();

    While true()
    {
        if (sp.IsOpen)
        {
            try
            {
                serialEvent(sp);
            }
            catch (Exception)
            {
                throw;
            }
        }

    }

    void serialEvent(SerialPort myPort)
    {
        string myString = myPort.ReadLine();
        if (myString != null)
        {
                Debug.Log("Read " + myString);
        }
    }
    SerialPort sp = new SerialPort("COM3", 9600);
sp.Open();

    While true()
    {
        if (sp.IsOpen)
        {
            try
            {
                serialEvent(sp);
            }
            catch (Exception)
            {
                throw;
            }
        }

    }

    void serialEvent(SerialPort myPort)
    {
        string myString = myPort.ReadLine();
        if (myString != null)
        {
                Debug.Log("Read " + myString);
        }
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

runtime crashing debugger crashing
C#CC# / help
2y ago
Style cop crashing?
C#CC# / help
5mo ago