Drawing data obtained from Serial Port progresively getting slowerVirtual Serial Port for LinuxHow to get the type of T from a member of a generic class or method?Get int value from enum in C#Get property value from string using reflection in C#How to Read and Write from the Serial PortGetting Serial Port InformationHow to open, read, and write from serial port in C?Fail to get data from serial portHow to read data from serial port and write to serial port?C# serial port can not get all data from com port
What could be my risk mitigation strategies if my client wants to contract UAT?
To exponential digit growth and beyond!
Why Emacs (dired+) asks me twice to delete file?
What did the 'turbo' button actually do?
Visual Block Mode edit with sequential number
What is the limit to a Glyph of Warding's trigger?
Goldfish unresponsive, what should I do?
What did Brienne write about Jaime?
Possibility of faking someone's public key
ifconfig shows UP while ip link shows DOWN
Why is 'additive' EQ more difficult to use than 'subtractive'?
Moons and messages
Testing using real data of the customer
How does the Earth's center produce heat?
Are runways booked by airlines to land their planes?
Piping the output of comand columns
Alexandrov's generalization of Cauchy's rigidity theorem
Is a world with one country feeding everyone possible?
Why'd a rational buyer offer to buy with no conditions precedent?
Are there historical examples of audiences drawn to a work that was "so bad it's good"?
Who wrote “A writer only begins a book. A reader finishes it.”
Is it safe to redirect stdout and stderr to the same file without file descriptor copies?
Align vertices between two edges
Point to polygon walking distance
Drawing data obtained from Serial Port progresively getting slower
Virtual Serial Port for LinuxHow to get the type of T from a member of a generic class or method?Get int value from enum in C#Get property value from string using reflection in C#How to Read and Write from the Serial PortGetting Serial Port InformationHow to open, read, and write from serial port in C?Fail to get data from serial portHow to read data from serial port and write to serial port?C# serial port can not get all data from com port
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am working on voltmeter application, that draws voltage waveform. Hardware sends 1000 numbers (range 0 - 1023, always whole numbers) in string format per second through serial port.
public SerialPort serialPort = new SerialPort("COM3", 57600);
serialPort.Open();
String is converted into int and then drawn with DrawLine into PictureBox.
// variable declarations, all is int, runs in its own thread
while (blToMeasure) // true after clicking on button
iPrevY = iY;
iY = Int16.Parse(serialPort.ReadLine());
graphicsGraph.DrawLine(penBlack, iX, iPrevY, iX + 1, iY);
// only this thread is accessing PictureBox
iX++;
if (iX > picBoxGraph.Width)
graphicsGraph.Clear(SystemColors.Control);
iX = 0;
if (iY > picBoxGraph.Height)
Issue is that drawing lines itself is fast as it should be only for a couple of seconds, but gets gradually slower.
I tried Int.Parse
, Int32.Parse
and splitting thread function multiple ways using lock (graphicsGraph)
(moving conditions with Clear into another thread) or using BlockingCollection<int>
(moving DrawLine into another thread, away from Parse). Nothing seems to work and app still gets slower a couple of times after like a minute of running.
There isn't issue with hardware itself, checked with another software. Is this too fast for C#?
c# serial-port drawing
|
show 3 more comments
I am working on voltmeter application, that draws voltage waveform. Hardware sends 1000 numbers (range 0 - 1023, always whole numbers) in string format per second through serial port.
public SerialPort serialPort = new SerialPort("COM3", 57600);
serialPort.Open();
String is converted into int and then drawn with DrawLine into PictureBox.
// variable declarations, all is int, runs in its own thread
while (blToMeasure) // true after clicking on button
iPrevY = iY;
iY = Int16.Parse(serialPort.ReadLine());
graphicsGraph.DrawLine(penBlack, iX, iPrevY, iX + 1, iY);
// only this thread is accessing PictureBox
iX++;
if (iX > picBoxGraph.Width)
graphicsGraph.Clear(SystemColors.Control);
iX = 0;
if (iY > picBoxGraph.Height)
Issue is that drawing lines itself is fast as it should be only for a couple of seconds, but gets gradually slower.
I tried Int.Parse
, Int32.Parse
and splitting thread function multiple ways using lock (graphicsGraph)
(moving conditions with Clear into another thread) or using BlockingCollection<int>
(moving DrawLine into another thread, away from Parse). Nothing seems to work and app still gets slower a couple of times after like a minute of running.
There isn't issue with hardware itself, checked with another software. Is this too fast for C#?
c# serial-port drawing
3
Not enough information to answer your question. Did you look into the serial port code? Maybe the reason is there, not in the drawing code. Furthermore, you normally are not allowed to access UI elements from background (non-UI) threads. There might be some huge graphic objects allocations in your code leading to memory pressure or handle leaks. Please consider providing a Minimal, Complete, and Verifiable example.
– dymanoid
Mar 17 at 18:15
1
Yes, an mcve can help you help yourself or salvage this question: make sure you decouple the graphics from ther serialport. See what happens when you replace Port.ReadLine() with Random.Next() .
– Henk Holterman
Mar 17 at 19:34
And @dymond is right about the threads. Did you disable CheckForIllegalCrossThreadCalls ?
– Henk Holterman
Mar 17 at 19:36
@dymanoid Serial port is as it is in the post. I just set portName and baudRate, everything else is default. I tried to measure time between each serial port read withStopwatch.ElapsedTicks
and I get 120-150 (0 in miliseconds all the time) in long term. I still suppose that the issue is with drawing (see next comment). The PictureBox is being used only by this thread. Main thread starts this one and then does nothing with this particular UI element. Thank you for that link, I am new here and this was very helpful. :)
– Kubees
Mar 17 at 20:11
1
If you found a solution, please consider posting it here as an answer. Answering own question is also accepted here, on StackOverflow, if that answer does provide some value for others. If it was only a typo in your code or bad software design, consider deleting your question as not relevant anymore.
– dymanoid
Mar 19 at 21:40
|
show 3 more comments
I am working on voltmeter application, that draws voltage waveform. Hardware sends 1000 numbers (range 0 - 1023, always whole numbers) in string format per second through serial port.
public SerialPort serialPort = new SerialPort("COM3", 57600);
serialPort.Open();
String is converted into int and then drawn with DrawLine into PictureBox.
// variable declarations, all is int, runs in its own thread
while (blToMeasure) // true after clicking on button
iPrevY = iY;
iY = Int16.Parse(serialPort.ReadLine());
graphicsGraph.DrawLine(penBlack, iX, iPrevY, iX + 1, iY);
// only this thread is accessing PictureBox
iX++;
if (iX > picBoxGraph.Width)
graphicsGraph.Clear(SystemColors.Control);
iX = 0;
if (iY > picBoxGraph.Height)
Issue is that drawing lines itself is fast as it should be only for a couple of seconds, but gets gradually slower.
I tried Int.Parse
, Int32.Parse
and splitting thread function multiple ways using lock (graphicsGraph)
(moving conditions with Clear into another thread) or using BlockingCollection<int>
(moving DrawLine into another thread, away from Parse). Nothing seems to work and app still gets slower a couple of times after like a minute of running.
There isn't issue with hardware itself, checked with another software. Is this too fast for C#?
c# serial-port drawing
I am working on voltmeter application, that draws voltage waveform. Hardware sends 1000 numbers (range 0 - 1023, always whole numbers) in string format per second through serial port.
public SerialPort serialPort = new SerialPort("COM3", 57600);
serialPort.Open();
String is converted into int and then drawn with DrawLine into PictureBox.
// variable declarations, all is int, runs in its own thread
while (blToMeasure) // true after clicking on button
iPrevY = iY;
iY = Int16.Parse(serialPort.ReadLine());
graphicsGraph.DrawLine(penBlack, iX, iPrevY, iX + 1, iY);
// only this thread is accessing PictureBox
iX++;
if (iX > picBoxGraph.Width)
graphicsGraph.Clear(SystemColors.Control);
iX = 0;
if (iY > picBoxGraph.Height)
Issue is that drawing lines itself is fast as it should be only for a couple of seconds, but gets gradually slower.
I tried Int.Parse
, Int32.Parse
and splitting thread function multiple ways using lock (graphicsGraph)
(moving conditions with Clear into another thread) or using BlockingCollection<int>
(moving DrawLine into another thread, away from Parse). Nothing seems to work and app still gets slower a couple of times after like a minute of running.
There isn't issue with hardware itself, checked with another software. Is this too fast for C#?
c# serial-port drawing
c# serial-port drawing
edited Mar 23 at 21:58
Kubees
asked Mar 17 at 18:06
KubeesKubees
13
13
3
Not enough information to answer your question. Did you look into the serial port code? Maybe the reason is there, not in the drawing code. Furthermore, you normally are not allowed to access UI elements from background (non-UI) threads. There might be some huge graphic objects allocations in your code leading to memory pressure or handle leaks. Please consider providing a Minimal, Complete, and Verifiable example.
– dymanoid
Mar 17 at 18:15
1
Yes, an mcve can help you help yourself or salvage this question: make sure you decouple the graphics from ther serialport. See what happens when you replace Port.ReadLine() with Random.Next() .
– Henk Holterman
Mar 17 at 19:34
And @dymond is right about the threads. Did you disable CheckForIllegalCrossThreadCalls ?
– Henk Holterman
Mar 17 at 19:36
@dymanoid Serial port is as it is in the post. I just set portName and baudRate, everything else is default. I tried to measure time between each serial port read withStopwatch.ElapsedTicks
and I get 120-150 (0 in miliseconds all the time) in long term. I still suppose that the issue is with drawing (see next comment). The PictureBox is being used only by this thread. Main thread starts this one and then does nothing with this particular UI element. Thank you for that link, I am new here and this was very helpful. :)
– Kubees
Mar 17 at 20:11
1
If you found a solution, please consider posting it here as an answer. Answering own question is also accepted here, on StackOverflow, if that answer does provide some value for others. If it was only a typo in your code or bad software design, consider deleting your question as not relevant anymore.
– dymanoid
Mar 19 at 21:40
|
show 3 more comments
3
Not enough information to answer your question. Did you look into the serial port code? Maybe the reason is there, not in the drawing code. Furthermore, you normally are not allowed to access UI elements from background (non-UI) threads. There might be some huge graphic objects allocations in your code leading to memory pressure or handle leaks. Please consider providing a Minimal, Complete, and Verifiable example.
– dymanoid
Mar 17 at 18:15
1
Yes, an mcve can help you help yourself or salvage this question: make sure you decouple the graphics from ther serialport. See what happens when you replace Port.ReadLine() with Random.Next() .
– Henk Holterman
Mar 17 at 19:34
And @dymond is right about the threads. Did you disable CheckForIllegalCrossThreadCalls ?
– Henk Holterman
Mar 17 at 19:36
@dymanoid Serial port is as it is in the post. I just set portName and baudRate, everything else is default. I tried to measure time between each serial port read withStopwatch.ElapsedTicks
and I get 120-150 (0 in miliseconds all the time) in long term. I still suppose that the issue is with drawing (see next comment). The PictureBox is being used only by this thread. Main thread starts this one and then does nothing with this particular UI element. Thank you for that link, I am new here and this was very helpful. :)
– Kubees
Mar 17 at 20:11
1
If you found a solution, please consider posting it here as an answer. Answering own question is also accepted here, on StackOverflow, if that answer does provide some value for others. If it was only a typo in your code or bad software design, consider deleting your question as not relevant anymore.
– dymanoid
Mar 19 at 21:40
3
3
Not enough information to answer your question. Did you look into the serial port code? Maybe the reason is there, not in the drawing code. Furthermore, you normally are not allowed to access UI elements from background (non-UI) threads. There might be some huge graphic objects allocations in your code leading to memory pressure or handle leaks. Please consider providing a Minimal, Complete, and Verifiable example.
– dymanoid
Mar 17 at 18:15
Not enough information to answer your question. Did you look into the serial port code? Maybe the reason is there, not in the drawing code. Furthermore, you normally are not allowed to access UI elements from background (non-UI) threads. There might be some huge graphic objects allocations in your code leading to memory pressure or handle leaks. Please consider providing a Minimal, Complete, and Verifiable example.
– dymanoid
Mar 17 at 18:15
1
1
Yes, an mcve can help you help yourself or salvage this question: make sure you decouple the graphics from ther serialport. See what happens when you replace Port.ReadLine() with Random.Next() .
– Henk Holterman
Mar 17 at 19:34
Yes, an mcve can help you help yourself or salvage this question: make sure you decouple the graphics from ther serialport. See what happens when you replace Port.ReadLine() with Random.Next() .
– Henk Holterman
Mar 17 at 19:34
And @dymond is right about the threads. Did you disable CheckForIllegalCrossThreadCalls ?
– Henk Holterman
Mar 17 at 19:36
And @dymond is right about the threads. Did you disable CheckForIllegalCrossThreadCalls ?
– Henk Holterman
Mar 17 at 19:36
@dymanoid Serial port is as it is in the post. I just set portName and baudRate, everything else is default. I tried to measure time between each serial port read with
Stopwatch.ElapsedTicks
and I get 120-150 (0 in miliseconds all the time) in long term. I still suppose that the issue is with drawing (see next comment). The PictureBox is being used only by this thread. Main thread starts this one and then does nothing with this particular UI element. Thank you for that link, I am new here and this was very helpful. :)– Kubees
Mar 17 at 20:11
@dymanoid Serial port is as it is in the post. I just set portName and baudRate, everything else is default. I tried to measure time between each serial port read with
Stopwatch.ElapsedTicks
and I get 120-150 (0 in miliseconds all the time) in long term. I still suppose that the issue is with drawing (see next comment). The PictureBox is being used only by this thread. Main thread starts this one and then does nothing with this particular UI element. Thank you for that link, I am new here and this was very helpful. :)– Kubees
Mar 17 at 20:11
1
1
If you found a solution, please consider posting it here as an answer. Answering own question is also accepted here, on StackOverflow, if that answer does provide some value for others. If it was only a typo in your code or bad software design, consider deleting your question as not relevant anymore.
– dymanoid
Mar 19 at 21:40
If you found a solution, please consider posting it here as an answer. Answering own question is also accepted here, on StackOverflow, if that answer does provide some value for others. If it was only a typo in your code or bad software design, consider deleting your question as not relevant anymore.
– dymanoid
Mar 19 at 21:40
|
show 3 more comments
1 Answer
1
active
oldest
votes
Solution:
I got the best results using Port.ReadTimeout = 1
and Port.DiscardInBuffer()
. Also using Form.DoubleBuffered = true
, but it doesn't make a huge difference in this particular case.
// constructor
Port.ReadTimeout = 1;
Form.DoubleBuffered = true;
Here is the loop itself:
btn.Click() // click to start measuring
Port.DiscardInBuffer();
blToMeasure = true;
while (blToMeasure) // true after clicking on button
iPrevY = iY;
try
iY = Int16.Parse(serialPort.ReadLine());
catch
// exception logic
graphicsGraph.DrawLine(penBlack, iX, iPrevY, iX + 1, iY);
// only this thread is accessing PictureBox
iX++;
if (iX > picBoxGraph.Width)
graphicsGraph.Clear(SystemColors.Control);
iX = 0;
if (iY > picBoxGraph.Height)
When the app starts to read from the port, there is always accumulated data, because my hardware is sending numbers all the time, so I get rid of the buffer. Than the drawing of lines is not executed in differing spikes and the speed is constant. Analyzing the issue with Watch
, I found out, that it occasionaly takes much longer to read this data and because of 1000 reads per second, it slows down. So to prevent slowing down, I used Port.ReadTimeout
, that skips the read, if it takes too long.
The difference is visible, drawing no longer slows down and it keeps the same pace for minutes from what I've tried. I consider this sufficient solution for my issue, thank you!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55210262%2fdrawing-data-obtained-from-serial-port-progresively-getting-slower%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Solution:
I got the best results using Port.ReadTimeout = 1
and Port.DiscardInBuffer()
. Also using Form.DoubleBuffered = true
, but it doesn't make a huge difference in this particular case.
// constructor
Port.ReadTimeout = 1;
Form.DoubleBuffered = true;
Here is the loop itself:
btn.Click() // click to start measuring
Port.DiscardInBuffer();
blToMeasure = true;
while (blToMeasure) // true after clicking on button
iPrevY = iY;
try
iY = Int16.Parse(serialPort.ReadLine());
catch
// exception logic
graphicsGraph.DrawLine(penBlack, iX, iPrevY, iX + 1, iY);
// only this thread is accessing PictureBox
iX++;
if (iX > picBoxGraph.Width)
graphicsGraph.Clear(SystemColors.Control);
iX = 0;
if (iY > picBoxGraph.Height)
When the app starts to read from the port, there is always accumulated data, because my hardware is sending numbers all the time, so I get rid of the buffer. Than the drawing of lines is not executed in differing spikes and the speed is constant. Analyzing the issue with Watch
, I found out, that it occasionaly takes much longer to read this data and because of 1000 reads per second, it slows down. So to prevent slowing down, I used Port.ReadTimeout
, that skips the read, if it takes too long.
The difference is visible, drawing no longer slows down and it keeps the same pace for minutes from what I've tried. I consider this sufficient solution for my issue, thank you!
add a comment |
Solution:
I got the best results using Port.ReadTimeout = 1
and Port.DiscardInBuffer()
. Also using Form.DoubleBuffered = true
, but it doesn't make a huge difference in this particular case.
// constructor
Port.ReadTimeout = 1;
Form.DoubleBuffered = true;
Here is the loop itself:
btn.Click() // click to start measuring
Port.DiscardInBuffer();
blToMeasure = true;
while (blToMeasure) // true after clicking on button
iPrevY = iY;
try
iY = Int16.Parse(serialPort.ReadLine());
catch
// exception logic
graphicsGraph.DrawLine(penBlack, iX, iPrevY, iX + 1, iY);
// only this thread is accessing PictureBox
iX++;
if (iX > picBoxGraph.Width)
graphicsGraph.Clear(SystemColors.Control);
iX = 0;
if (iY > picBoxGraph.Height)
When the app starts to read from the port, there is always accumulated data, because my hardware is sending numbers all the time, so I get rid of the buffer. Than the drawing of lines is not executed in differing spikes and the speed is constant. Analyzing the issue with Watch
, I found out, that it occasionaly takes much longer to read this data and because of 1000 reads per second, it slows down. So to prevent slowing down, I used Port.ReadTimeout
, that skips the read, if it takes too long.
The difference is visible, drawing no longer slows down and it keeps the same pace for minutes from what I've tried. I consider this sufficient solution for my issue, thank you!
add a comment |
Solution:
I got the best results using Port.ReadTimeout = 1
and Port.DiscardInBuffer()
. Also using Form.DoubleBuffered = true
, but it doesn't make a huge difference in this particular case.
// constructor
Port.ReadTimeout = 1;
Form.DoubleBuffered = true;
Here is the loop itself:
btn.Click() // click to start measuring
Port.DiscardInBuffer();
blToMeasure = true;
while (blToMeasure) // true after clicking on button
iPrevY = iY;
try
iY = Int16.Parse(serialPort.ReadLine());
catch
// exception logic
graphicsGraph.DrawLine(penBlack, iX, iPrevY, iX + 1, iY);
// only this thread is accessing PictureBox
iX++;
if (iX > picBoxGraph.Width)
graphicsGraph.Clear(SystemColors.Control);
iX = 0;
if (iY > picBoxGraph.Height)
When the app starts to read from the port, there is always accumulated data, because my hardware is sending numbers all the time, so I get rid of the buffer. Than the drawing of lines is not executed in differing spikes and the speed is constant. Analyzing the issue with Watch
, I found out, that it occasionaly takes much longer to read this data and because of 1000 reads per second, it slows down. So to prevent slowing down, I used Port.ReadTimeout
, that skips the read, if it takes too long.
The difference is visible, drawing no longer slows down and it keeps the same pace for minutes from what I've tried. I consider this sufficient solution for my issue, thank you!
Solution:
I got the best results using Port.ReadTimeout = 1
and Port.DiscardInBuffer()
. Also using Form.DoubleBuffered = true
, but it doesn't make a huge difference in this particular case.
// constructor
Port.ReadTimeout = 1;
Form.DoubleBuffered = true;
Here is the loop itself:
btn.Click() // click to start measuring
Port.DiscardInBuffer();
blToMeasure = true;
while (blToMeasure) // true after clicking on button
iPrevY = iY;
try
iY = Int16.Parse(serialPort.ReadLine());
catch
// exception logic
graphicsGraph.DrawLine(penBlack, iX, iPrevY, iX + 1, iY);
// only this thread is accessing PictureBox
iX++;
if (iX > picBoxGraph.Width)
graphicsGraph.Clear(SystemColors.Control);
iX = 0;
if (iY > picBoxGraph.Height)
When the app starts to read from the port, there is always accumulated data, because my hardware is sending numbers all the time, so I get rid of the buffer. Than the drawing of lines is not executed in differing spikes and the speed is constant. Analyzing the issue with Watch
, I found out, that it occasionaly takes much longer to read this data and because of 1000 reads per second, it slows down. So to prevent slowing down, I used Port.ReadTimeout
, that skips the read, if it takes too long.
The difference is visible, drawing no longer slows down and it keeps the same pace for minutes from what I've tried. I consider this sufficient solution for my issue, thank you!
answered Mar 23 at 22:04
KubeesKubees
13
13
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55210262%2fdrawing-data-obtained-from-serial-port-progresively-getting-slower%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Not enough information to answer your question. Did you look into the serial port code? Maybe the reason is there, not in the drawing code. Furthermore, you normally are not allowed to access UI elements from background (non-UI) threads. There might be some huge graphic objects allocations in your code leading to memory pressure or handle leaks. Please consider providing a Minimal, Complete, and Verifiable example.
– dymanoid
Mar 17 at 18:15
1
Yes, an mcve can help you help yourself or salvage this question: make sure you decouple the graphics from ther serialport. See what happens when you replace Port.ReadLine() with Random.Next() .
– Henk Holterman
Mar 17 at 19:34
And @dymond is right about the threads. Did you disable CheckForIllegalCrossThreadCalls ?
– Henk Holterman
Mar 17 at 19:36
@dymanoid Serial port is as it is in the post. I just set portName and baudRate, everything else is default. I tried to measure time between each serial port read with
Stopwatch.ElapsedTicks
and I get 120-150 (0 in miliseconds all the time) in long term. I still suppose that the issue is with drawing (see next comment). The PictureBox is being used only by this thread. Main thread starts this one and then does nothing with this particular UI element. Thank you for that link, I am new here and this was very helpful. :)– Kubees
Mar 17 at 20:11
1
If you found a solution, please consider posting it here as an answer. Answering own question is also accepted here, on StackOverflow, if that answer does provide some value for others. If it was only a typo in your code or bad software design, consider deleting your question as not relevant anymore.
– dymanoid
Mar 19 at 21:40