本文介绍了无效的跨线程访问.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好
打开应用程序时,我试图在消息框中显示我的吐司通知,但是我收到无效的跨线程访问".尝试调用messagebox.show时出错.这是我的代码.
Hi
I am trying to display my toast notifacation in messagebox when app is open however i get an "Invalid cross-thread access." error when trying to call the messagebox.show. here is my code.
void myShowAlertChannel_ShellToastNotificationReceived( 对象 发件人,NotificationEventArgs e) |
{ |
:11px> (e.Collection != 空 ) |
{ |
Dictionary< blue span> , 字符串 > collection = (字典< 字符串 , 字符串 >)e.Collection; |
; messageBuilder = 新 System.Text.StringBuilder(); |
字符串 ToastMessage = " ; |
 s color:blue> foreach ( string elementName in collection.Values) |
nbsp; b |
b ; ToastMessage = + elementName; sp ; |
} |
 s color:blue>字符串 szTitle = "我的显示提示" ; ; |
字符串 szMessage = "警告: " + ToastMessage ; |
s ; szMessage); |
} |
} |
私有 void ShowMessageAlert( 字符串 标题, 字符串 消息) |
{ |
MessageBox.Show(Message, Title, |
} |
void myShowAlertChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) |
{ |
if (e.Collection != null) |
{ |
Dictionary<string, string> collection = (Dictionary<string, string>)e.Collection; |
System.Text.StringBuilder messageBuilder = new System.Text.StringBuilder(); |
string ToastMessage = ""; |
foreach (string elementName in collection.Values) |
{ |
ToastMessage = ToastMessage + elementName; |
} |
string szTitle = "My Show Alert"; |
string szMessage = "Alert: " + ToastMessage; |
ShowMessageAlert(szTitle, szMessage); |
} |
} |
private void ShowMessageAlert(string Title, string Message) |
{ |
MessageBox.Show(Message, Title, MessageBoxButton.OK); |
} |
推荐答案
这篇关于无效的跨线程访问.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!