Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing WPF Form Elements from inside async Task<T>
#1
Good day.  This code seemed to have worked before, but now I'm getting the dreaded:
 
Code:
Copy      Help
System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.


Here is a code snippet...  This is inside an async Task<bool> method....

I put the "print.it" and "return" statements in to see if I was getting an error from the static method RequestLicense.  But the exception moved to the print.it line for licenseName.Text.  Thoughts for retrieving the value from the form and passing it to the static method?

Thanks!

C# code:
        var b = new wpfBuilder("License Request Info").WinSize(400);
        b.R.Add("Full Name", out TextBox licenseName).Focus();
        b.R.Add("Email Address", out TextBox licenseEmail);
        b.R.AddOkCancel();
        b.End();
        if (!b.ShowDialog())
            return false; // quit
        
        
        var isOnline = await CheckConn();
        if (isOnline == true) { // we can communicate with the license server
            print.it(licenseName.Text);
            print.it(licenseEmail.Text);
            return false;
            var licReq = RequestLicense(licenseName.Text, licenseEmail.Text, "standard");


Messages In This Thread
Accessing WPF Form Elements from inside async Task<T> - by netdude78 - 05-16-2022, 03:32 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)