Stackoverflow in System.Windows.Forms.dll

Asked

Viewed 93 times

0

Hello. I am developing a C# desktop application that performs a Serial Port routine (Writing, Reading, Capturing Information, Displaying this information). However, there are times when a Stack Overflow error appears, but each hour is in a different row

Error:

An unhandled Exception of type 'System.Stackoverflowexception' occurred in System.Windows.Forms.dll

I got most of it already developed by another person who worked here at the company.

Follow Full code on link: https://docs.google.com/document/d/1Hip8mTZbjIljme6Q0e60XVUEcc1YUnLrwWgpR0LaG_w/pub

  • 3

    How is the code? It is possible to put it in question?

  • Yes. I’ll organize and put it.

  • @Eduardomatheus only with this section not to know, the problem may be bursting there but was caused by another section. On which line is the error pointed?

  • I put another part of the code.

  • Placing random snippets will not help.

  • I put in the Docs the complete Code.

  • @Eduardomatheus add the stack trace exception the question and join the relevant code (the code around the line where the stack trace indicates that there was an exception). As it is near impossible to understand (until the code in the link this chaotic).

  • 1

    @Daniloloko Thanks! Perfectly solved the problem.

  • Please administrators, consider reopening the question so that I can ask the answer and withdraw from the comments, as the question was not clear but the question was considered difficult. Grateful.

  • @Daniloloko reopened. Please add more info to the question to make it clearer as well. Then me or another mod can clear the comments here if they mark them as obsolete.

Show 5 more comments

1 answer

0


Stathreadattribute is essentially a requirement for Windows to perform communication with COM components. However, Windowsforms does not use COM components. Therefore, access to serial ports and other components are necessary to be added the [Stathread] in your way.

Example:

[STAThread] //adicionado
private void buscaSensores()
{
...

MSDN demonstrates more details of the use of the same.

Stathreadattribute indicates that the COM threading model for the application is single-threaded Apartment. This attribute must be present on the entry point of any application that uses Windows Forms; if it is omitted, the Windows Components Might not work correctly. If the attribute is not present, the application uses the multithreaded Apartment model, which is not supported for Windows Forms.

For more details: What does [Stathread] do?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.