小编Moo*_*oon的帖子

Windows服务:OnPowerEvent不会触发

我想创建一个Windows服务来跟踪是否插入了A/C电源适配器.为此,我正在尝试构建如下的Windows服务:

using System;
using System.ServiceProcess;

namespace PowerAlert {
    partial class PowerAlert : ServiceBase {
        public PowerAlert() {
            InitializeComponent();
        }

        protected override void OnStart(string[] args) {
            base.OnStart(args);
        }

        protected override void OnStop() {
            base.OnStop();
        }

        protected new virtual void OnPowerEvent(PowerBroadcastStatus powerStatus) {
            Console.Beep();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

安装服务并从services.msc启动它后,当我拔下我的适配器并将其重新插入时,我听不到哔声.

我确信我没有正确地做某事.你能帮我识别那些/那些东西吗?

编辑1

从下面可以看出,CanHandlePowerEvent设置为true.

namespace PowerAlert {
    partial class PowerAlert {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used. …
Run Code Online (Sandbox Code Playgroud)

.net c# service windows-services

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

使用SQL Server正则表达式过滤带有垃圾字符的行

在我的表中,某些行在某些列中有垃圾字符,如Ё㺞稹㾸䐶㩜癈癈.我试图过滤掉如下所示的行:

SELECT Col1, Col2, Col3 FROM MyTable WHERE Col2 NOT LIKE '%[REGEX]%'
Run Code Online (Sandbox Code Playgroud)
  1. 有没有更好的方法?
  2. 如果不是,我怎样才能生成正确的正则表达式?我不想要任何记录,其中Col2只有字母数字字符,标点和空格.

regex sql sql-server

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

WPF:UserControl的Command和CommandParameter

我正在创建一个习惯,UserControl并希望UC有一个CommandButton.我是WPF的新手.

这是我迄今为止没有运气的尝试:

WelcomeView.xaml

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="150"/>
    </Grid.RowDefinitions>

    <Controls:SignedButton Grid.Row="1" VerticalAlignment="Top" Width="245" Height="45" Foreground="#FFFFFF" 
                           LeftSign="+" Text="Add an account" TextSize="20" 
                           ButtonBackground="#3A5795" HoverBackground="#C41AD7" HoverOpacity="1"
                           Command="{x:Static Infrastructure:ApplicationCommands.NavigateCommand}" 
                           CommandParameter="{x:Type Views:AddAccountView}"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)

SignedButton.xaml.cs

public partial class SignedButton : UserControl
{

    public static DependencyProperty ButtonBackgroundProperty =
        DependencyProperty.Register("ButtonBackground", typeof (string), typeof (SignedButton));

    public static DependencyProperty CommandParameterProperty =
        DependencyProperty.Register("CommandParameter", typeof (object), typeof (SignedButton));

    public static DependencyProperty CommandProperty =
        DependencyProperty.Register("Command", typeof (ICommand), typeof (SignedButton));

    public static DependencyProperty HoverBackgroundProperty =
        DependencyProperty.Register("HoverBackground", typeof …
Run Code Online (Sandbox Code Playgroud)

wpf user-controls prism wpf-controls

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

c#:什么是线程轮询?

当一个人说你的线程解决方案没有被允许时,这是什么意思,因为它是浪费的,它有延迟,而且是非确定性的.线程不应该使用轮询来互相发出信号.

编辑

根据您到目前为止的答案,我相信下面的线程实现(取自:http://www.albahari.com/threading/part2.aspx#_AutoResetEvent)不使用轮询.如果我错了,请纠正我.

using System;
using System.Threading;
using System.Collections.Generic;

class ProducerConsumerQueue : IDisposable {
  EventWaitHandle _wh = new AutoResetEvent (false);
  Thread _worker;
  readonly object _locker = new object();
  Queue<string> _tasks = new Queue<string>();

  public ProducerConsumerQueue() (
    _worker = new Thread (Work);
    _worker.Start();
  }

  public void EnqueueTask (string task) (
    lock (_locker) _tasks.Enqueue (task);
    _wh.Set();
  }

  public void Dispose() (
    EnqueueTask (null);     // Signal the consumer to exit.
    _worker.Join();         // Wait for the consumer's thread to finish. …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading

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

Ruby on Rails:解压缩(Zlib :: Deflate)在一定时间后不起作用

我需要在将大块文本保存到数据库之前压缩大块文本,并在客户端请求后将其解压缩.

当我使用Rails控制台插入新记录并立即查询新插入的记录时,我现在使用的方法似乎工作正常.即,我可以成功解压缩压缩的描述.

但是我无法解压缩description此日期之前添加的任何其他记录的压缩文件.对我来说真的很困惑,尤其是作为ROR世界的新手.

MySQL用作数据库.

你能指点我正确的方向吗?请看下面的模型,以便更好地理解它.

require "base64"

class Video < ActiveRecord::Base
  before_save :compress_description

  def desc
    unless description.blank?
      return decompress(description)
    end
  end

  private

  def compress_description
    unless description.blank?
      self.description = compress(description)
    end
  end

  def compress(text)
    Base64.encode64(Zlib::Deflate.new(nil, -Zlib::MAX_WBITS).deflate(text, Zlib::FINISH))
  end

  def decompress(text)
    Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(Base64.decode64(text))
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby mysql ruby-on-rails zlib ruby-on-rails-3

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

最新的ember.js(1.0.0.0)无法识别"find"和"createRecord"

我刚升级到最新的ember.js.在那之后,我的应用程序开始失败.

这是Firebug输出:

DEBUG: -------------------------------
DEBUG: Ember      : 1.0.0
DEBUG: Ember Data : 1.0.0-beta.2
DEBUG: Handlebars : 1.0.0
DEBUG: jQuery     : 1.10.2
DEBUG: -------------------------------

Attempting URL transition to /
Transition #1: Beginning validation for transition to clocks.index
Transition #1: application: calling beforeModel hook
Transition #1: application: resolving model
Transition #1: application: calling afterModel hook
Transition #1: application: validation succeeded, proceeding
Transition #1: clocks: calling beforeModel hook
Transition #1: clocks: resolving model
Transition #1: clocks.index: transition was aborted
Transition #1: clocks: handling …
Run Code Online (Sandbox Code Playgroud)

ember.js

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

c#:控制从不同线程访问对象

如何控制允许线程访问对象的时间以及何时不允许该线程访问对象.

例如,如果我有下面的情况,我想确保当我在ButtonClick事件中使用objFoo做某事时,我不能从我的doSomethingWithObjFoo方法触摸objFoo.

private void button1_Click(object sender, EventArgs e) {
    // doing something with objFoo
}

private void timer1_Tick(object sender, EventArgs e) {
    Thread T = new Thread(new ThreadStart(doSomethingWithObjFoo));
    T.Start();
}

private void doSomethingWithObjFoo(){
    // doing something else with objFoo
}
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading thread-safety

0
推荐指数
1
解决办法
1929
查看次数