C#C
C#2y ago
Mek

✅ make function sleep without freezing ui avalonia

public void LoginScreen()
{
    var vm = new LoginViewModel();

    Observable.Merge(
        vm.Ok,
        vm.Cancel
        .Select(_ => (UserModel?)null))
        .Take(1)
        .Subscribe(model =>
        {
            if (model != null)
            {
                LoggedInUser.Username = model.Username;
            }
            else
            {
                Environment.Exit(0);
            }
        });

    Content = vm;
}
this is my function for the MainWindowViewModel. and this is my ViewModel that matches the LoginViewModel vm https://pastebin.com/uDpQL2cR.

  1. My first issue is that in my ReturnUser model, I can't figure out what to return in the if/else if clauses.
  2. My second issue is that when i click the Exit button, it's almost immediate. It takes a second or two and then the window closes, but then if I just leave username and password blank and click login, it takes nearly 6 seconds to figure whatever it needs to out and then it displays that the login was successful ...
  3. which leads into #3 before #1 became an issue, I did have it to where the else clause was outside of the if statment and not in an else clause so that the code would execute if the check systems didn't fail, however, I think there was a problem with my check system. This is a link to the copy of the code that comes before #1 being an issue https://pastebin.com/jsb8nsqA
I'm not really sure what to do. I would like to keep the code I had before #1 became an issue as I was working on cleaning it up and making it better if we could go that route with this code https://pastebin.com/jsb8nsqA

MainWindowViewModel.cs (for reference): https://pastebin.com/R8e77kDa
Was this page helpful?