8,757
社区成员
发帖
与我相关
我的任务
分享 private void readMonitorInfor()
{
EndpointAddress address = new EndpointAddress(new Uri(Application.Current.Host.Source, "/AndonInforService.svc"));
AndonInforServiceClient client = new AndonInforServiceClient(new BasicHttpBinding(), address);
client.readMonitorInforCompleted += client_readMonitorInforCompleted;
client.readMonitorInforAsync();
}
你的wcf的使用是有问题的,最好不要反复的使用新的wcf,这样开销很大的。
应该定义一个全局的 wcf实例,然后每次只是用这个实例,如:
在你的构造函数中
public partial class MainPage : UserControl
{
private ServiceReference1.Service1Client _wcf ;
public MainPage()
{
InitializeComponent();
_wcf = new Service1Client();
_wcf.readMonitorInforCompleted +=(s,e)
{
try
{
dataGrid1.ItemsSource = null;
dataGrid1.ItemsSource = e.Result;
}
catch (Exception error)
{
MessageBox.Show("网络中断,请检查网络连接!\n" +"在确认网络连接正常后刷新页面!");
timer.Stop();
//MessageBox.Show(error.ToString());
}
}
}
}
另外对话框和timer.stop不应该出现在这里,因为定时器周期性执行,这里应该发个事件有别的地方处理。
还有,我的回答有一段与你的主题无关的内容,那是回答别人的发到你这里了,见谅。