如何从线程显示 Infragistics 的 UltraDesktopAlert
我已经面临很多天的问题了。我有一个线程正在监听来自其他系统的通知。每当我通过套接字收到通知时,我想使用 Infragistics 的 UltraDesktopAlert 控件将其显示在警报窗口中。这个类库中没有winform。
请告诉我如何使用线程显示它。示例在这里
void tcpServerListenter_OnCommReceive(object sender, CommEventArgs e)
{
string xmlString = Encoding.UTF8.GetString((byte[])e.data);
try
{
XDocument xmlDoc = XDocument.Parse(xmlString);
var res = (from msg in xmlDoc.Descendants("consoleNotification")
select msg.Element("value").Value).FirstOrDefault();
this.notificationMsg = res;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// here Alert window is not displaying.
ultraDesktopAlert1.Show("Notification", this.notificationMsg);
}
,但此代码不显示警报窗口。
我还检查了以下链接 如何从 C# 中的另一个线程更新 GUI?
但问题是我的类库中没有 Winform。每当我在套接字上收到通知时,我想显示警报窗口。
i am facing problem from many days. I have a thread listening for notificaitons from other system. whenever i receive a notification over socket i want to display it in Alert window using Infragistics's UltraDesktopAlert control. there is no winform in this class library.
please tell me how to display it using a thread. a sample is here
void tcpServerListenter_OnCommReceive(object sender, CommEventArgs e)
{
string xmlString = Encoding.UTF8.GetString((byte[])e.data);
try
{
XDocument xmlDoc = XDocument.Parse(xmlString);
var res = (from msg in xmlDoc.Descendants("consoleNotification")
select msg.Element("value").Value).FirstOrDefault();
this.notificationMsg = res;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// here Alert window is not displaying.
ultraDesktopAlert1.Show("Notification", this.notificationMsg);
}
but this code is not displaying alert window.
i checked the following link also
How to update the GUI from another thread in C#?
but problem is that i have no Winform in my class library. what i wants to display alert window whenever i receive notification on socket.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是保存 UI 线程的同步上下文并将 lambda 发送到 UI 线程...
在 UI 线程上,启动异步操作时/之前...
将其保存到正在执行 aSync 的类中工作,然后您想要发送代码以在保存的同步上下文上运行。
请注意,如果您需要从 UI 线程检索 Current SynchronizationContext,则无法从非 UI 线程获取 UI 线程同步上下文。
The easiest way to do this is save the UI thread's synchronization context and Send a lambda over to the UI thread...
On the UI Thread, when/before initiating your Async operation...
Save this into the class that is doing the aSync work, then you want to Send your code to run on the saved synchronization context.
Note that if you need to retrieve the Current SynchronizationContext from the UI thread, you can't get the UI threads synchronization context from a non UI thread.
您需要执行安全的跨线程,因为 ultraDesktopAlert1 Infragistics 对象是由主线程创建的,但在不同的线程上访问。
请查看此 MSDN 文档,了解如何执行此操作。
You need to do safe cross threading since the ultraDesktopAlert1 Infragistics object was created by the main thread but being accessed on a different thread.
Check out this MSDN Documentation on how to do it.