C# windows form crash

Isacco Simonini 5 Reputation points
2024-03-13T10:22:08.48+00:00

Hi,

I'm writing my Windows forms project in C# using the latest versione available of Visual Studio Community (17.9.3).

The project manages a Modbus TCP client connection using the NModbus library to a proprietary and tested server. The connection is established as soon as i click a button.

Testing the project on my laptop is not an issue, the issue is when I use either the Debug or the Release versions on another laptop. As soon as I start the connection on any other laptop I tried (2), the connection is established for a couple of seconds, then it simply crashes.

I installed Visual Studio on one of the two laptops and the very same project runs smoothly only if that project is recompiled on that device.

I'm thinking about some settings in the compilation routine but I can't get the hang of it, do you have any suggestion?

Just to give some more data about it, I've placed exception cases everywhere, using message boxes aas well in order to have as much debugging as possible but nothing seems to give a feedback, the project just crashes down a few seconds after connection is established.

Thanks

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,903 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,012 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Jiale Xue - MSFT 46,466 Reputation points Microsoft Vendor
    2024-03-13T12:01:14.5066667+00:00

    Hi @Isacco Simonini , Welcome to Microsoft Q&A,

    You said you were able to establish a connection but it would crash after a few seconds without any feedback. This is not normal.

    Without an error message, it's not clear what the specific error is.

    Check the firewall settings on the other laptops to make sure they are not blocking Modbus TCP connections to the server. Sometimes firewalls block access to specific ports or IP addresses.

    Because you only tested the second computer, this does not necessarily mean there is a problem with your program.

    You also need to decide whether to test the Modbus TCP server independently to see if it can connect to other computers.

    Create a simple program to test it out.

    Check for resource leaks, such as connections not being closed properly or resources released. If resources are not released properly in your code, it can cause resource exhaustion after a long run, causing the connection to crash. Make sure you close the connection properly and release related resources when you are finished using it.

    Check for concurrent access issues; multiple threads may be accessing the connection at the same time, causing race conditions and erratic behavior. Ensure proper synchronization and thread safety measures when accessing connections to avoid concurrent access issues.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.