Skip to content

Commit

Permalink
Merge pull request #50 from watte1997/FixSlaveDisConnect
Browse files Browse the repository at this point in the history
Fixed disconnect button cannot stop connection.
  • Loading branch information
graham22 authored Sep 27, 2024
2 parents 727518e + 4b3f368 commit c980019
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ModbusSlave/ModbusSlave.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
12 changes: 7 additions & 5 deletions ModbusSlave/SlaveForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ private void DoDisconnect()
_uart.Dispose();
_uart = null;
}

if (_socket != null)
{
_socket.Dispose();
_socket = null;
}

if (_thread != null && _thread.IsAlive)
{
if (_thread.Join(2000) == false)
Expand All @@ -162,11 +169,6 @@ private void DoDisconnect()
_thread = null;
}
}
if (_socket != null)
{
_socket.Dispose();
_socket = null;
}
}

#endregion
Expand Down

0 comments on commit c980019

Please sign in to comment.