Click here to Skip to main content
15,894,247 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,please when i have wrong? if I run the program occurs exception UnauthorizedAccessException
SerialPort serial = new SerialPort("COM4", 9600);
        Timer timer = new Timer();
        public Form1()
        {
            InitializeComponent();
            timer.Interval=5;
            timer.Tick += new EventHandler(aktivuj);

        }
        public void aktivuj(object sender,EventArgs e)
        {
            string s;
            Invalidate();
            serial.Open();
            serial.Write(textBox1.Text.ToString());
            s = serial.ReadLine();
            serial.Close();
            label1.Text = s;
        }
Posted
Comments
Sergey Alexandrovich Kryukov 2-Apr-15 17:31pm    
In what line?
Why, why coupling communication code with UI that badly? Why opening and closing by timer? Why?
—SA

1 solution

Absolutely wrong idea is reading from the device using the timer. If you have UnauthorizedAccessException (in what line?) execute your code as administrator, just to see what's going on.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900