public Dictionary <string, string> ReciveData(bool modal) { var notNeedTimeout = networkTimeout < 0; var recordsCount = -1; var modalWindow = new NetworkSynchronizeForm(); var passed = 0; Dictionary <string, string> result = new Dictionary <string, string>(); try { if (modal) { modalWindow.Show(); } while (passed < networkTimeout || notNeedTimeout) { if (_networkServer.Objects.Count > 0) { if (recordsCount <= 0) { if (_networkServer.Objects[0].message1 != "count") { throw new ArgumentNullException(); } int.TryParse(_networkServer.Objects[0].message2, out recordsCount); if (recordsCount <= 0) { throw new FormatException(); } _networkServer.Objects.RemoveAt(0); } if (recordsCount > 0 && _networkServer.Objects.Count >= recordsCount) { result = _networkServer.Objects.Take(recordsCount).Select(x => Transform(x)).ToDictionary(x => x.Key, x => x.Value); _networkServer.Objects.RemoveRange(0, recordsCount); break; } } Thread.Sleep(1000); passed += 1; } if (modal) { modalWindow.Close(); } } catch (Exception) { } return(result); }
public Dictionary<string, string> ReciveData(bool modal) { var notNeedTimeout = networkTimeout < 0; var recordsCount = -1; var modalWindow = new NetworkSynchronizeForm(); var passed = 0; Dictionary<string, string> result = new Dictionary<string, string>(); try { if (modal) modalWindow.Show(); while (passed < networkTimeout || notNeedTimeout) { if (_networkServer.Objects.Count > 0) { if (recordsCount <= 0) { if (_networkServer.Objects[0].message1 != "count") throw new ArgumentNullException(); int.TryParse(_networkServer.Objects[0].message2, out recordsCount); if (recordsCount <= 0) throw new FormatException(); _networkServer.Objects.RemoveAt(0); } if (recordsCount > 0 && _networkServer.Objects.Count >= recordsCount) { result = _networkServer.Objects.Take(recordsCount).Select(x => Transform(x)).ToDictionary(x => x.Key, x => x.Value); _networkServer.Objects.RemoveRange(0, recordsCount); break; } } Thread.Sleep(1000); passed += 1; } if (modal) modalWindow.Close(); } catch (Exception) { } return result; }