How to handle lock statement if there is an external api call in between
===

I have the following code:

    private static HashSet<SoloUser> soloUsers = new HashSet<SoloUser>();
       
        public void findNewPartner(string School, string Major)
        {
            lock (soloUsers)
            {
                SoloUser soloUser = soloUsers.FirstOrDefault(s => (s.School == School) && (s.Major == Major));
                MatchConnection matchConn;
                if (soloUser != null)
                {
                    if (soloUser.ConnectionId != Context.ConnectionId)
                    {
                        string Token = TokenHelper.GenerateToken(soloUser.Session)
                                              
                        soloUsers.Remove(soloUser);

                    }

                }
                else
                {   string session = "mysession";                                     
                    string token = TokenHelper.GenerateModeratorToken(session);
                    soloUser = new SoloUser
                    {
                        Major = Major,
                        School = School,
                        SessionId = sessionId,
                        ConnectionId = Context.ConnectionId
                    };
                    
                    soloUsers.Add(soloUser);

                    
                }

            } 
            
        }

`TokenHelper.GenerateToken(soloUser.Session)` and `TokenHelper.GenerateModeratorToken(session);` could be hazardous because they may take a moment to generate a token.  This will lock all users out for a that moment which could be a problem?  Are there any workarounds to this logic so that I can still keep everything threadsafe?