Click here to Skip to main content
15,892,927 members
Home / Discussions / C#
   

C#

 
GeneralRe: Why am I not allowed to do this with events Pin
Keith Barrow9-Oct-20 3:19
professionalKeith Barrow9-Oct-20 3:19 
QuestionHow to read from serial port until timeout of no more data received? Pin
td17768-Oct-20 13:27
td17768-Oct-20 13:27 
AnswerRe: How to read from serial port until timeout of no more data received? Pin
Luc Pattyn8-Oct-20 14:27
sitebuilderLuc Pattyn8-Oct-20 14:27 
GeneralRe: How to read from serial port until timeout of no more data received? Pin
td17768-Oct-20 15:36
td17768-Oct-20 15:36 
GeneralRe: How to read from serial port until timeout of no more data received? Pin
Luc Pattyn9-Oct-20 1:25
sitebuilderLuc Pattyn9-Oct-20 1:25 
AnswerRe: How to read from serial port until timeout of no more data received? Pin
Gerry Schmitz8-Oct-20 18:27
mveGerry Schmitz8-Oct-20 18:27 
GeneralRe: How to read from serial port until timeout of no more data received? Pin
td17769-Oct-20 11:16
td17769-Oct-20 11:16 
GeneralRe: How to read from serial port until timeout of no more data received? Pin
Gerry Schmitz9-Oct-20 14:10
mveGerry Schmitz9-Oct-20 14:10 
AnswerRe: How to read from serial port until timeout of no more data received? Pin
Richard MacCutchan8-Oct-20 22:55
mveRichard MacCutchan8-Oct-20 22:55 
AnswerMy (temporary?) solution Pin
td17769-Oct-20 11:25
td17769-Oct-20 11:25 
QuestionCOM exception loss Pin
Member 126326017-Oct-20 20:57
Member 126326017-Oct-20 20:57 
AnswerRe: COM exception loss Pin
Richard MacCutchan7-Oct-20 21:35
mveRichard MacCutchan7-Oct-20 21:35 
GeneralRe: COM exception loss Pin
Member 126326017-Oct-20 22:03
Member 126326017-Oct-20 22:03 
GeneralRe: COM exception loss Pin
Richard MacCutchan7-Oct-20 22:25
mveRichard MacCutchan7-Oct-20 22:25 
GeneralRe: COM exception loss Pin
Member 126326017-Oct-20 22:58
Member 126326017-Oct-20 22:58 
GeneralRe: COM exception loss Pin
Richard MacCutchan7-Oct-20 23:24
mveRichard MacCutchan7-Oct-20 23:24 
AnswerRe: COM exception loss Pin
OriginalGriff8-Oct-20 4:10
mveOriginalGriff8-Oct-20 4:10 
QuestionScanning for servers Pin
pkfox4-Oct-20 21:52
professionalpkfox4-Oct-20 21:52 
AnswerRe: Scanning for servers Pin
Richard Deeming5-Oct-20 2:44
mveRichard Deeming5-Oct-20 2:44 
The UspClient class implements IDisposable, so you could try wrapping it in a using block.

I'd also be inclined to use local variables for objects which aren't meant to live beyond the current method, rather than storing everything in class-level fields.
C#
public async Task<LMSResponseParser> ScanForServer()
{
    using (var listener = new UdpClient(UDPPort))
    {
        this.ReceiveIP = new IPEndPoint(IPAddress.Broadcast, UDPPort);
        
        var result = await listener.ReceiveAsync();
        var requestData = result.Buffer;
        this.ReceiveIP = result.RemoteEndPoint;
        
        this.BytesSent = await listener.SendAsync(requestData, requestData.Length, this.ReceiveIP);
        
        result = await listener.ReceiveAsync();
        var bytesReceived = result.Buffer;
        if (bytesReceived != null && bytesReceived.Length != 0)
        {
            this.RetVal = Encoding.UTF8.GetString(bytesReceived);
        }
        
        return new LMSResponseParser(bytesReceived);
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Scanning for servers Pin
pkfox5-Oct-20 3:44
professionalpkfox5-Oct-20 3:44 
GeneralRe: Scanning for servers Pin
pkfox5-Oct-20 4:17
professionalpkfox5-Oct-20 4:17 
Questionversion mismatch Pin
Member 149246074-Oct-20 9:30
Member 149246074-Oct-20 9:30 
AnswerRe: version mismatch Pin
Richard Deeming5-Oct-20 2:33
mveRichard Deeming5-Oct-20 2:33 
GeneralRe: version mismatch Pin
Member 149246075-Oct-20 7:45
Member 149246075-Oct-20 7:45 
GeneralRe: version mismatch Pin
Richard Deeming5-Oct-20 21:22
mveRichard Deeming5-Oct-20 21:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.