C# Listen code trouble in BeginInvoke

07/19/2020 15:37 leandro5#1
Closed this
07/19/2020 22:36 Mikesch01#2
This code has so many flaws.

- Never run logic in a catch
- NEVER RUN ASNYC CODE IN A CATCH
- Never let a catch empty
- Use while instead of goto-loops
- Remove unnecessary code

- Use english as your coding language
- Use SOLID principle
- Use clean code

This code is unreadable.
07/22/2020 17:05 leandro5#3
Quote:
Originally Posted by Mikesch01 View Post
This code has so many flaws.

- Never run logic in a catch
- NEVER RUN ASNYC CODE IN A CATCH
- Never let a catch empty
- Use while instead of goto-loops
- Remove unnecessary code

- Use english as your coding language
- Use SOLID principle
- Use clean code

This code is unreadable.
Thanks for the feedback and seems i found where was the problemwas calling endinvoke inside ProcederAceitar i just changed it and now call it's after result where begininvoke is called:

Code:
                if (OnAceitar != null)
                {
                    IAsyncResult result;
                    Console.WriteLine("OnAceitar != null client: {0} Handle: {1}", handler.RemoteEndPoint, handler.Handle);
                    result = OnAceitar.BeginInvoke(client, new AsyncCallback(ProcederAceitar), client);
                    OnAceitar.EndInvoke(result);
                    Console.WriteLine("iAsyncResult OnAceitar.BeginInvoke: " + result.AsyncState);
                }
Code:
        private void ProcederAceitar(IAsyncResult ar)
        {
            if (Fexando)
            {
                Console.WriteLine("ProcederAceitar Fexando igual a true");
                return;
            }

            //OnAceitar.EndInvoke(ar);
09/29/2021 06:44 tehpwnerer69#4
Quote:
Originally Posted by Mikesch01 View Post
- Never let a catch empty
I gotta disagree with you here, especially when handling procedures that will always throw off an error and you simply want to catch it and nothing more

E.g. attempting a ParseFloat inside of a try catch statement, inside of a boolean.

If you know what the exception is, you know it's not harmful and that it's not just floating around in memory, then what harm can this really do? Nothing and it is common practice for professional coders to
catch(Exception e){}//and thats all
Because why handle something that need not be handled?

So I disagree on this key point here
Keep in mind I didn't see the code posted