Open SkyTheComputerGuy opened 3 months ago
I assume you've debugged to ensure no exceptions are thrown and that you're indeed on the correct dispatcher thread for ColorRec. If you want to be sure you can grab the dispatcher directly off ColoRec (in case it differs from MainPage...though it shouldn't). Keep in mind the Button_Click will already be called in the UI thread, whereas AppServices call will come on a threadpool thread. So it seems like you're dispatch logic in Button_click is redundant, but you are seemingly doing the right thing for RunAsync.
I'm not as familiar with C# threading behavior as I am with C++/WinRT. However, in C++/WinRT you have to be careful that resuming from co_await on anything other than IAsyncAction/Operation can result in resumption on a threadpool thread. Perhaps your await dialog.ShowAsync() resumes on a threadpool thread instead of back on the dispatcher thread. I would liter some threadid debug logs at various points to study what's going on.
It is definitely not because of the await's, since even if you remove the dialog boxes, the color still does not update. I even added these lines in both the SetInputAsync (before and after the awaits, and even without the dlg box ) and the in-widget button click:
Debug.WriteLine($"Thread: {Environment.CurrentManagedThreadId}");
and both times it was 'Thread: 4'
So maybe it is because of how the WPF app connects to the AppService or maybe it is a bug?
Coming from assembler and C+, C# is really having a toll on me. Thank you for your reply!
Hello!
I’m experiencing an issue with a Xbox Game Bar widget where a Rectangle element’s Fill property is not visually updating as expected when receiving a request from a WPF app. I was wondering If I could get some assistance here.
Context: (Projects are not packaged)
The Issue: (Code Snippets are below)
When the widget receives the request from the WPF app, the 'ColorRec' rectangle is supposed to change color from red to green, but it does not. (Rectangles initial Fill="Red")
The code in the _'AppServiceConnectionRequestReceived' method (defined in App.xaml.cs), specifically the SetInputAsync (defined in MainPage.xaml.cs) method is supposed to change the color
However:
After the first click the message box shows the Fill property as the color #FFFF0000 (red), after the color change the message box shows #FF008000 (green), but the actual color of the rectangle in the launched widget (from Win+G -> Widgets) does not change. Subsequent message boxes from the request path show that the color of the ColorRec.Fill is indeed #FF008000 (still green), yet the color of the rectangle stays red.
As a test I also have a button in the widget, when clicked it also shows a message box with the type of color of the rectangle, although no matter at what time it is pressed, the color always shows as Red (#FFFF0000). Meaning that even though the message boxes from the request body show Green, the click shows Red. If the color change directive in the button click handler is uncommented the color of the rectangle changes and it updates visibly in the widget.
This has led me to believe it has something to do with which thread calls what methods, or something of that sort? Any help would be really appreciated. Thank you.
Code Snippets: