private async Task <AddScheduleResult> _AddSchedule(ClassSchedule schedule) { if (CurrentStudent == null) { return(null); } if (Server == null) { await FindServer(); } if (Server == null) { return(null); } AddScheduleResult result = null; NetworkComms.AppendGlobalIncomingPacketHandler <AddScheduleResult>(AddScheduleResult.GetHeader(), (h, c, i) => { NetworkComms.RemoveGlobalIncomingPacketHandler(AddScheduleResult.GetHeader()); result = i; }); await new AddSchedule() { ClassId = schedule.ClassId, StudentId = CurrentStudent.StudentId, TransactionId = TransactionId }.Send(new IPEndPoint(IPAddress.Parse(Server.IP), Server.Port)); var start = DateTime.Now; while ((DateTime.Now - start).TotalSeconds < 17) { if (result != null) { return(result); } await Task.Delay(TimeSpan.FromSeconds(1)); } Server = null; NetworkComms.RemoveGlobalIncomingPacketHandler(AddScheduleResult.GetHeader()); return(null); }
public static async Task <AddScheduleResult> AddSchedule(ClassSchedule schedule) { return(await Instance._AddSchedule(schedule)); }