0

I have a simple code, which send from server to clients value to count. This loop count for 9 value, from 1 to 9. Everything work good for 1,3 or 9 clients. But for other number of clients when i_wiersz has value 9 and foreach loop want sent something to another client server break down. Ho make, to work with any one numbers of clients?

I try put inside foreach loop:

if(i_wiersz == 9)
   break;

but a get an error: Error

Control cannot leave the body of an anonymous method or lambda expression

My code:

bool spr_wiersz(int wiersz, int kolumna) //chck_roow(int roow, int column)
{
   wys_tab();
   int i_wiersz = 0;
   bool[] result = new bool[9];

   while (i_wiersz < 9)
   {
      subscribers.ForEach(delegate(ImessageCallback callback)
      {
          if (((ICommunicationObject)callback).State == CommunicationState.Opened)
          {
              result[i_wiersz] = callback.spr_wiersz(wiersz, kolumna, i_wiersz);
              i_wiersz++;
          }
      });

      for (int j = 0; j < i_wiersz; j++)
      {
          if (result[j] == false)
          {
             return false;
          }
      }
   }

   return true;
}
1

1 Answer 1

1

Can’t you simply convert it to a traditional foreach?

  foreach (IMessageCallback callback in subscribers)
  {
      if (((ICommunicationObject)callback).State == CommunicationState.Opened)
      {
          result[i_wiersz] = callback.spr_wiersz(wiersz, kolumna, i_wiersz);
          i_wiersz++;

          if (i_wiersz == 9)
              break;
      }
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.