Пример #1
0
        private static async void MainThreadProc()
        {
            if (Session.SessionManager.State == Session.SessionManager.SessionState.Unauthorized)
            {
                var authRes = await SessionManager.Authorize(SessionManager.Username, SessionManager.Password);

                if (authRes == SessionManager.SessionState.Unauthorized)
                {
                    return;
                }
            }

            while (true)
            {
                if (DataRequests.Count <= 0)
                {
                    Thread.Sleep(10);
                    continue;
                }

                KeyValuePair <DataType, DataCallback> req = DataRequests.First.Value;
                DataRequests.RemoveFirst();


                ISmartClient Client = OnlineClient;

                object result = req.Key switch
                {
                    DataType.MyUser => await Client.GetMyUser(),
                    DataType.Friendships => await Client.GetFriendships(),
                    DataType.Groups => await Client.GetGroups(),
                    DataType.Memberships => await Client.GetMemberships(),
                    _ => null
                };

                if (result != null)
                {
                    req.Value(result);
                }
            }
        }