1 回答
TA贡献1794条经验 获得超8个赞
Visibility是一个 UI 属性,必须在 UI 线程上设置。在您的情况下,它将在ConnectionReceived事件处理程序运行的同一线程上运行(感谢async/await),这可能不是 UI 线程。您应该改为Visibility在Dispatcher.RunAsync调用中设置 以确保它在 UI 线程上运行。
private async void StreamSocketListener_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
{
string request;
using(var streamReader = new StreamReader(args.Socket.InputStream.AsStreamForRead()))
{
request = await streamReader.ReadLineAsync();
}
var setVisibility = request.Length > 0;
await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
this.txtBlk_Events.Text = request;
if ( setVisibility )
{
btnSend.Visibility = Visibility.Visible;
}
});
}
- 1 回答
- 0 关注
- 153 浏览
添加回答
举报