Click here to Skip to main content
14,734,133 members
Home » Discussions » C#
   

C#

 
AnswerRe: COM exception loss Pin
Richard MacCutchan7-Oct-20 22:35
mveRichard MacCutchan7-Oct-20 22:35 
GeneralRe: COM exception loss Pin
Member 126326017-Oct-20 23:03
MemberMember 126326017-Oct-20 23:03 
GeneralRe: COM exception loss Pin
Richard MacCutchan7-Oct-20 23:25
mveRichard MacCutchan7-Oct-20 23:25 
GeneralRe: COM exception loss Pin
Member 126326017-Oct-20 23:58
MemberMember 126326017-Oct-20 23:58 
GeneralRe: COM exception loss Pin
Richard MacCutchan8-Oct-20 0:24
mveRichard MacCutchan8-Oct-20 0:24 
AnswerRe: COM exception loss Pin
OriginalGriff8-Oct-20 5:10
mveOriginalGriff8-Oct-20 5:10 
QuestionScanning for servers Pin
pkfox4-Oct-20 22:52
professionalpkfox4-Oct-20 22:52 
AnswerRe: Scanning for servers Pin
Richard Deeming5-Oct-20 3:44
mveRichard Deeming5-Oct-20 3: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.
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 4:44
professionalpkfox5-Oct-20 4:44 
GeneralRe: Scanning for servers Pin
pkfox5-Oct-20 5:17
professionalpkfox5-Oct-20 5:17 
Questionversion mismatch Pin
Member 149246074-Oct-20 10:30
MemberMember 149246074-Oct-20 10:30 
AnswerRe: version mismatch Pin
Richard Deeming5-Oct-20 3:33
mveRichard Deeming5-Oct-20 3:33 
GeneralRe: version mismatch Pin
Member 149246075-Oct-20 8:45
MemberMember 149246075-Oct-20 8:45 
GeneralRe: version mismatch Pin
Richard Deeming5-Oct-20 22:22
mveRichard Deeming5-Oct-20 22:22 
QuestionprintDocument Pin
Member 149437371-Oct-20 20:02
MemberMember 149437371-Oct-20 20:02 
AnswerRe: printDocument Pin
Gerry Schmitz1-Oct-20 20:11
mveGerry Schmitz1-Oct-20 20:11 
GeneralRe: printDocument Pin
Member 149437371-Oct-20 23:54
MemberMember 149437371-Oct-20 23:54 
AnswerRe: printDocument Pin
OriginalGriff1-Oct-20 21:03
mveOriginalGriff1-Oct-20 21:03 
GeneralRe: printDocument Pin
Member 149437371-Oct-20 23:37
MemberMember 149437371-Oct-20 23:37 
GeneralRe: printDocument Pin
OriginalGriff1-Oct-20 23:40
mveOriginalGriff1-Oct-20 23:40 
QuestionHow to compare on DPFP.Template to another DPFP.Template Pin
Member 144684061-Oct-20 4:07
MemberMember 144684061-Oct-20 4:07 
AnswerRe: How to compare on DPFP.Template to another DPFP.Template Pin
Gerry Schmitz1-Oct-20 5:49
mveGerry Schmitz1-Oct-20 5:49 
GeneralRe: How to compare on DPFP.Template to another DPFP.Template Pin
Member 144684061-Oct-20 9:39
MemberMember 144684061-Oct-20 9:39 
GeneralRe: How to compare on DPFP.Template to another DPFP.Template Pin
Gerry Schmitz2-Oct-20 5:31
mveGerry Schmitz2-Oct-20 5:31 
GeneralRe: How to compare on DPFP.Template to another DPFP.Template Pin
Member 144684062-Oct-20 21:35
MemberMember 144684062-Oct-20 21:35 

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.