小编use*_*808的帖子

性能计数器当前进程的CPU使用率超过100

我想显示我的多线程应用程序的CPU使用率(在多核处理器上工作).我想收到任务经理附近的数字.但我得到的数字超过100%.甚至超过500%.是的,我知道,对于类别"进程"的计数器"%Processor Time",我需要分为Environment.ProcessorCount"NumberOfLogicalProcessors"(我的配置相同).此操作结果为500%.我在具有不同硬件(i7,i5,Core2)和软件配置(带有所有更新的Windows 7 SP1,带有所有更新的Windows 2008 R2 SP1)的不同计算机上测试了此示例,并遇到了同样的问题.

public static class SystemInfo
{
    private static Process _thisProc;
    private static bool HasData = false;
    private static PerformanceCounter _processTimeCounter;

    private static void Init()
    {
        if (HasData)
            return;

        if (CheckForPerformanceCounterCategoryExist("Process"))
        {
            _processTimeCounter = new PerformanceCounter();
            _processTimeCounter.CategoryName = "Process";
            _processTimeCounter.CounterName = "% Processor Time";
            _processTimeCounter.InstanceName = FindInstanceName("Process");
            _processTimeCounter.NextValue();
        }

        MaximumCpuUsageForCurrentProcess = 0;
        HasData = true;
    }

    private static bool CheckForPerformanceCounterCategoryExist(string categoryName)
    {
        return PerformanceCounterCategory.Exists(categoryName);
    } …
Run Code Online (Sandbox Code Playgroud)

c# process performancecounter cpu-usage

14
推荐指数
1
解决办法
2万
查看次数

用于多线程应用程序的无头浏览器

我正在为.NET多线程应用程序寻找无头浏览器.它必须具有下一个功能:

  • 没有任何服务器安装工作.我需要简单的库来分发我的应用程序.
  • Ajax/HTML 5支持.能够处理页面元素:通过内部/外部(SGMLReader)XML查找和读取属性,或使用API​​单击按钮,填写表单等.
  • 正确的cookie容器(正确使用多个cookie响应并在所有会话期间存储cookie)
  • 可自定义的浏览器行(甚至选择Chrome/Firefox就足够了)
  • 多线程.所以没有静态cookie容器或smth.其他.我需要能够在2-100000不同的用户下登录和使用同一个站点.
  • 快速工作
  • 使用不安全的SSL使用https.

我找到了这个解决方案

但不知道什么是最好的.如果您建议我最好的解决方案并给出一些使用它的.NET示例,将会很高兴.

我读了这个,这个,以及其他许多答案,我还没有找到答案.

.net browser automation headless web-scraping

9
推荐指数
0
解决办法
680
查看次数

将装配中的所有autofac模块注册一行

我可以Autofac使用这样的行逐个注册所有模块(从Autofac.Module派生的类)

builder.RegisterModule(new LoggingInjectionModule());

但是,如果我有10个或更多模块,我只想指定程序集,哪里Autofac可以找到所需的模块,需要注册.有没有办法通过单行或两行注册特定程序集,命名空间中的所有模块?

.net ioc-container autofac

7
推荐指数
1
解决办法
3457
查看次数

多线程应用程序中的SQLite“数据库已锁定”错误

有一个多线程应用程序,可以处理较大的DB文件(> 600 Mb)。当我添加Blob数据时开始出现“数据库已锁定”问题,并且每个请求开始使用大于30 Kb的BLOB数据进行操作。我认为问题与小硬盘速度有关。看起来SQLite删除了-journal文件,我的应用程序的一个线程失锁了(因为-journal文件已被应用并删除了),而我的其他线程想对数据库进行处理,但是SQLite仍在更新DB文件...当然,我可以在每次DB调用后延迟一分钟,但这不是解决方案,因为我需要更快的速度。

现在,我使用每个会话(每个线程)实现的会话。因此,每个应用程序对象有一个ISessionFactory,而许多ISession对象是。

有我的帮助程序类(如您所见,我使用IsolationLevel.Serializable和CurrentSessionContext = ThreadStaticSessionContext):

public abstract class nHibernateHelper
{
    private static FluentConfiguration _configuration;
    private static IPersistenceContext _persistenceContext;

    static nHibernateHelper() {}

    private static FluentConfiguration ConfigurePersistenceLayer()
    {
        return Fluently.Configure().Database(FluentNHibernate.Cfg.Db.SQLiteConfiguration.Standard.ShowSql().UsingFile(_fileName).IsolationLevel(IsolationLevel.Serializable).MaxFetchDepth(2)).
                Mappings(m => m.FluentMappings.AddFromAssemblyOf<Foo>()).CurrentSessionContext(typeof(ThreadStaticSessionContext).FullName);
    }

    public static ISession CurrentSession
    {
        get { return _persistenceContext.CurrentSession; }
    }

    public static IDisposable OpenConnection()
    {
        return new DbSession(_persistenceContext);
    }
}

public class PersistenceContext : IPersistenceContext, IDisposable
{
    private readonly FluentConfiguration _configuration;
    private readonly ISessionFactory _sessionFactory;

    public PersistenceContext(FluentConfiguration configuration)
    {
        _configuration = configuration;
        _sessionFactory = …
Run Code Online (Sandbox Code Playgroud)

c# sqlite nhibernate multithreading locking

5
推荐指数
1
解决办法
6476
查看次数

如何理解 Process.Threads.Count 结果?这个变量显示什么?

让我们编写简单的控制台应用程序(调试模式):

    static void Main(string[] args)
    {
        Process p = Process.GetCurrentProcess();

        IList<Thread> threads = new List<Thread>();
        Console.WriteLine(p.Threads.Count);
        for(int i=0;i<30;i++)
        {
            Thread t = new Thread(Test);
            Console.WriteLine("Before start: {0}", p.Threads.Count);
            t.Start();
            Console.WriteLine("After start: {0}", p.Threads.Count);
        }
        Console.WriteLine(Process.GetCurrentProcess().Threads.Count);
        Console.ReadKey();
    }

    static void Test()
    {
        for(int i=0;i<100;i++)Thread.Sleep(1);
    }
Run Code Online (Sandbox Code Playgroud)

你认为你会在结果中看到什么?

[Q1] 为什么 p.Threads.Count 与 Process.GetCurrentProcess().Threads.Count 不同?

.net multithreading

4
推荐指数
1
解决办法
720
查看次数