C# 如何将通知项数据传递到datagrid?

C# 如何将通知项数据传递到datagrid?,c#,wpf,C#,Wpf,嗨,我正在从事一个项目,该项目将启动并收集服务器信息CPU、MEM、HDD使用情况等。。我目前有一个工作版本,有点凌乱。 我试图使它更具动态性(最终结果将是从数据库中提取服务器信息) 我试图传递我从我的机器收集的数据,并将数据传递到找到的每个服务器(名称、CPU、MEM等)的数据网格中 下面是我的代码: 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.Windows; 使用System.Windows.C

嗨,我正在从事一个项目,该项目将启动并收集服务器信息CPU、MEM、HDD使用情况等。。我目前有一个工作版本,有点凌乱。 我试图使它更具动态性(最终结果将是从数据库中提取服务器信息)

我试图传递我从我的机器收集的数据,并将数据传递到找到的每个服务器(名称、CPU、MEM等)的数据网格中

下面是我的代码:


使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用系统线程;
使用System.Net.NetworkInformation;
使用制度管理;
使用System.Windows.Threading;
使用System.Collections.ObjectModel;
名称空间Sat_测试
{
公共部分类主窗口:窗口
{
私人调度员定时器1;
公共主窗口()
{
初始化组件();
这个.SetUpTimer();
Dispatchermer Clock=new Dispatchermer(新的时间跨度(0,0,1),DispatcherPriority.Normal,委托{this.Clock.Text=DateTime.Now.ToString(“HH:mm:ss”);},this.Dispatcher);
}
私有void SetUpTimer()
{
timer1=新的调度程序();
timer1.Interval=TimeSpan.From毫秒(100);
timer1.Tick+=OnTimerTick;
timer1.Start();
}
私有void OnTimerTick(对象发送方,事件参数e)
{            
这个。Start();
}
私有void Start()
{
foreach(Items()中的var item)
{
ThreadPool.QueueUserWorkItem((o)=>
{
item.CheckService();
});
}
}
私有IEnumerable Items()
{
返回新的NotifyItem{ServerName=“127.0.0.1”,HDD1=“'C:”,ConnectionString=“SQLConnectionstring1”};
返回新的NotifyItem{ServerName=“127.0.0.1”,HDD1=“'C:”,ConnectionString=“SQLConnectionstring1”};
返回新的NotifyItem{ServerName=“127.0.0.1”,HDD1=“'C:”,ConnectionString=“SQLConnectionstring1”};
}
公共类通知项
{
私人时间=10;
公共字符串连接字符串{get;set;}
公共字符串ServerName{get;set;}
公共映像映像{get;set;}
公共字符串HDD1{get;set;}
公共作废检查服务()
{
字符串host=ServerName;
布尔结果=假;
Ping p=新Ping();
尝试
{
PingReply reply=p.Send(主机,pingTime);
if(reply.Status==IPStatus.Success)
结果=真;
}
捕获{}
如果(结果)
{
//Image.Visibility=可见性.Visibility;
dostufforserver();
}
}
公共字符串GetServerFullName()
{
字符串名称=”;
ConnectionOptions选项=新的ConnectionOptions();
//options.Username=usr;
//选项。密码=pwd;
options.Impersonation=ImpersonationLevel.Impersonate;
options.Authentication=AuthenticationLevel.Default;
options.EnablePrivileges=true;
ManagementScope=new ManagementScope(“\\\\”+ServerName+“\\root\\CIMV2”,选项);
ObjectQuery=新建ObjectQuery(“从Win32_ComputerSystem中选择*);
ManagementObjectSearcher getcpu=新的ManagementObjectSearcher(范围、查询);
foreach(getcpu.Get()中的ManagementObject对象)
{
Name=string.Concat(obj[“Name”].ToString());
}
返回名称;
}
public void dostufforserver()
{                                      
字符串serverFullName=GetServerFullName();
int cpuData=Convert.ToInt16(GetCPU());
int memData=Convert.ToInt16(GetMEM());
double hdd1Data=Math.Truncate(GetHDD1()*100)/100;
}
私有双GetHDD1()
{
ConnectionOptions选项=新的ConnectionOptions();
//options.Username=usr;
//选项。密码=pwd;
options.Impersonation=ImpersonationLevel.Impersonate;
options.Authentication=AuthenticationLevel.Default;
options.EnablePrivileges=true;
ManagementScope=new ManagementScope(“\\\\”+ServerName+“\\root\\CIMV2”,选项);
ObjectQuery=new ObjectQuery(“从Win32_LogicalDisk中选择*,其中Name=“+HDD1+”);
ManagementObjectSearcher getcpu=新的ManagementObjectSearcher(范围、查询);
双HDD总=0;
双HDDfree=0;
foreach(getcpu.Get()中的ManagementObject对象)
{
HDDfree=double.Parse(obj[“FreeSpace”].ToString());
}
返回(HDDfree/1024/1024/1024);
}
私有双GetMEM()
{
ConnectionOptions选项=新的ConnectionOptions();
//options.Username=usr;
//选项。密码=pwd;
options.Impersonation=ImpersonationLevel.Impersonate;
options.Authentication=AuthenticationLevel.Default;
options.EnablePrivileges=true;
ManagementScope=new ManagementScope(“\\\\”+ServerName+“\\root\\CIMV2”,选项);
ObjectQuery查询=新建ObjectQu