WMI搜索开始变慢 [英] WMI search started going slow

查看:65
本文介绍了WMI搜索开始变慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,在尝试发送任何内容之前,需要查询打印机的状态.如果认为打印机的状态无效,则将作业发送到第二台打印机(在检查该打印机状态之后).不会在打印之前向用户显示选择打印机的打印对话框,但是在应用程序配置中设置了具有主打印机和辅助打印机的各种报告的目的地.

以下代码用于查询命名打印机的状态,并且在过去8到9个月内一直正常工作.在例程周围放置一些跟踪时间,在查询打印机状态并返回结果的一秒钟内执行得很好.

I''ve an application the needs to query the state of a printer before attempting to send it anything. If the status of the printer is deemed not valid, the job is sent to a seconday printer (after that printer status is also checked). The user is not displayed a print dialog to select a printer prior to printing, but the destination of various reports with primary and secondary printers are set-up in the application config.

The following code is used to query the state of a named printer, and has been working fine for the past 8-9 months. Placing some trace timings around the routine, it''s been executing well under a second to query the printer status and return the result.

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer"))
{
  ManagementObject moPrinter = null;
  foreach (ManagementObject mo in searcher.Get())
    if (mo["Name"].ToString().ToLower() == printerName.ToLower())
    {
      moPrinter = mo;
      break;
    }
  if (moPrinter != null)
  {
    int status = Int32.Parse(moPrinter["PrinterStatus"].ToString());
    result = !((status == 1) || (status == 7));
  }
}



但是,此后,我的客户打电话给我,说在处理订单后给他们的客户打印一封信需要30到60秒才能完成,因此大大降低了他们的生产率.安装具有跟踪时间的应用程序版本可以突出显示以下例程,现在使用WMI大约需要20-30秒来检查打印机状态,而无需花费一秒钟.

我没有更改代码,那么导致WMI结果延迟增加的原因是什么?我相信这是他们的网络,但是当我是开发人员而不是网络人员时,我应该从哪里开始.我应该改变这个程序吗?我可以检查什么或让他们的IT人员检查?用户权限是否有效(使用XP的用户权限)?添加新的打印机或特定的网络软件是否有效?是否应该/不应该运行任何服务?

任何帮助或指导将不胜感激.

安德鲁:confused:



However, my client has since called me to say that printing a letter to their client after processing an order is taking 30-60 seconds to complete, therefore drastically reducing their productivity. Installing a version of my application with trace timings highlights the following routine is now taking around 20-30 seconds to check the printer status using WMI, rather than under a second.

I''ve not changed the code, so what''s caused this increased delay in getting WMI results? I beleive it''s their network, but where do I start as I''m a developer not a network guy. Should I change this routine? What can I check or get their IT guys to check? Does user permission have an effect (their using XP)? Does adding new printers or specific network software have an effect? Any services that should/should not be running?

Any help or guidance would be appreciated.

Andrew :confused:

推荐答案

我不知道是什么原因导致您提到的问题,但是您可以尝试搜索特定的打印机对象而不是所有打印机.

查询SELECT * FROM Win32_Printer WHERE Name = ''pRinTeR''还返回名为"Printer""PRINTER"的打印机.
您不需要获取所有打印机,让WMI来完成工作.
I don''t know what might cause the problem you mentioned, but you may try to search for the specific printer object instead of all printers.

The query SELECT * FROM Win32_Printer WHERE Name = ''pRinTeR'' also returns the printer named "Printer" oder "PRINTER".
You don''t need to fetch all printers, let WMI do the work.


这篇关于WMI搜索开始变慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆