C#中,让线程挂起

C#中,让线程挂起。不能使用Thead.Suspend(), 这个函数在.NET中已经被否决了,具体原因没有深入研究。微软推荐使用System.Threading中的函数,比如Monitor, Mutex, Event等。

在QQ好友空间访客提取的项目中我使用了ManualResetEvent这个Event类,具体用法如下:

类字段定义:

private ManualResetEvent _event = new ManualResetEvent (true ); //线程事件
private bool _pause = false; //线程是否暂停

工作线程函数中:

if (_pause)
{
     SetStatus( "已暂停");
}
_event.WaitOne();

暂停函数中:

SetStatus("暂停中...");
_event.Reset();
_pause = true;

恢复函数中:

if (_pause)
{
     //to resume thread
     _event.Set();
     _pause = false;

     return;
}

IIS服务器遭遇用户上传图片后,显示无权访问的问题

IIS服务器遭遇用户上传图片后,显示无权访问的问题,错误信息如下:

HTTP 错误 401.3 – Unauthorized
由于 Web 服务器上此资源的访问控制列表(ACL)配置或加密设置,您无权查看此目录或页面

解决办法:

1、打开站点的身份验证

2、在匿名身份验证上点右键菜单,然后点编辑 

3、把匿名用户标识改为“应用程序池标识“

最后点击确定并重启站点后OK(没有测试不重启站点的情况下是不是也可以生效)

centos安装LAMP记录

centos安装LAMP记录

wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.10.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.1.tar.gz
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
tar -xvf httpd-2.4.10.tar.gz
tar -xvf apr-1.5.1.tar.gz
tar -xvf apr-util-1.5.4.tar.gz
mv apr-1.5.1 httpd-2.4.10/srclib/apr
mv apr-util-1.5.4 httpd-2.4.10/srclib/apr-util
cd httpd-2.4.10
yum -y install pcre-devel.x86_64
./configure  --prefix=/web/httpd --with-included-apr --enable-nonportable-atomics=yes --with-z
make
make install
cp /web/httpd/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
#!/bin/sh下加上
# chkconfig: 35 85 15
# description: Activates/Deactivates Apache 2.4.10
chkconfig --add httpd
chkconfig httpd on

以下是配置httpd
vi /web/httpd/conf/httpd.conf
修改 ServerName 为 127.0.0.1:80

———————————————- 以下是PHP

http://cn2.php.net/distributions/php-5.6.4.tar.bz2
tar -xvf  php-5.6.4.tar.bz2
cd php-5.6.4
yum install libxml2-devel gd-devel libmcrypt-devel libcurl-devel openssl-devel
./configure --prefix=/web/php --with-apxs2=/web/httpd/bin/apxs --enable-cli --enable-shared --with-libxml-dir --with-gd --with-openssl --enable-mbstring --with-mcrypt --with-mysqli --with-mysql --enable-opcache --enable-mysqlnd --enable-zip --with-zlib-dir --with-pdo-mysql --with-jpeg-dir --with-freetype-dir --with-curl --without-pdo-sqlite --without-sqlite3
make
make install
cp php.ini-development /web/php/lib/php.ini

vim /web/php/lib/php.ini
查找 date.timezone,修改为Asia/Shanghai

vim /web/httpd/conf/httpd.conf
查找 AddType application/x-gzip .gz .tgz
在下一行添加:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps


查找DirectoryIndex index.html
在下一行添加
index.php

最后是修改httpd.conf的httpdocs目录,以及支持.htaccess。就不写了。

—————————————————–以下是MYSQL
安装yum install mysql mysql-server


启动 service mysqld start


配置 /usr/bin/mysql_secure_installation


开机启动 chkconfig mysqld on


登录数据库

mysql -p

开启root远程访问

grant all privileges on *.* to 'root'@'%' identified by 'xinyangwu' with grant option;

FLUSH PRIVILEGES;

SQL SERVER 生成数据库表对应的实体类的存储过程

SQL SERVER 生成数据库表对应的实体类的存储过程

CREATE PROCEDURE [dbo].[CreateModel]   
    @tableName varchar(100 )
AS
BEGIN
SET NOCOUNT ON;

-- Subquery to return only the copy paste text
Select PropertyColumn from (
    SELECT 1 as rowNr, 'public class ' + @tableName + ' {' as PropertyColumn
    UNION
    SELECT 2 as rowNr, 'public ' + a1. NewType + ' ' + a1.COLUMN_NAME + ' {get;set;}' as PropertyColumn
    -- ,* comment added so that i get copy pasteable output
     FROM
    (
        /*using top because i'm putting an order by ordinal_position on it.
        putting a top on it is the only way for a subquery to be ordered*/
        SELECT TOP 100 PERCENT
        COLUMN_NAME ,
        DATA_TYPE ,
        IS_NULLABLE ,
        CASE
            WHEN DATA_TYPE = 'varchar' THEN 'string'
            WHEN DATA_TYPE = 'nvarchar' THEN 'string'
            WHEN DATA_TYPE = 'datetime' AND IS_NULLABLE = 'NO' THEN 'DateTime'
            WHEN DATA_TYPE = 'datetime' AND IS_NULLABLE = 'YES' THEN 'DateTime?'
            WHEN DATA_TYPE = 'smalldatetime' AND IS_NULLABLE = 'NO' THEN 'DateTime'
            WHEN DATA_TYPE = 'datetime2' AND IS_NULLABLE = 'NO' THEN 'DateTime'
            WHEN DATA_TYPE = 'smalldatetime' AND IS_NULLABLE = 'YES' THEN 'DateTime?'
            WHEN DATA_TYPE = 'datetime2' AND IS_NULLABLE = 'YES' THEN 'DateTime?'
            WHEN DATA_TYPE = 'int' AND IS_NULLABLE = 'YES' THEN 'int?'
            WHEN DATA_TYPE = 'int' AND IS_NULLABLE = 'NO' THEN 'int'
            WHEN DATA_TYPE = 'smallint' AND IS_NULLABLE = 'NO' THEN 'Int16'
            WHEN DATA_TYPE = 'smallint' AND IS_NULLABLE = 'YES' THEN 'Int16?'
            WHEN DATA_TYPE = 'decimal' AND IS_NULLABLE = 'NO' THEN 'decimal'
            WHEN DATA_TYPE = 'decimal' AND IS_NULLABLE = 'YES' THEN 'decimal?'
            WHEN DATA_TYPE = 'numeric' AND IS_NULLABLE = 'NO' THEN 'decimal'
            WHEN DATA_TYPE = 'numeric' AND IS_NULLABLE = 'YES' THEN 'decimal?'
            WHEN DATA_TYPE = 'money' AND IS_NULLABLE = 'NO' THEN 'decimal'
            WHEN DATA_TYPE = 'money' AND IS_NULLABLE = 'YES' THEN 'decimal?'
            WHEN DATA_TYPE = 'bigint' AND IS_NULLABLE = 'NO' THEN 'long'
            WHEN DATA_TYPE = 'bigint' AND IS_NULLABLE = 'YES' THEN 'long?'
            WHEN DATA_TYPE = 'tinyint' AND IS_NULLABLE = 'NO' THEN 'byte'
            WHEN DATA_TYPE = 'tinyint' AND IS_NULLABLE = 'YES' THEN 'byte?'
            WHEN DATA_TYPE = 'char' THEN 'string'                       
            WHEN DATA_TYPE = 'timestamp' THEN 'byte[]'
            WHEN DATA_TYPE = 'varbinary' THEN 'byte[]'
            WHEN DATA_TYPE = 'bit' AND IS_NULLABLE = 'NO' THEN 'bool'
            WHEN DATA_TYPE = 'bit' AND IS_NULLABLE = 'YES' THEN 'bool?'
            WHEN DATA_TYPE = 'xml' THEN 'string'
        END AS NewType
        FROM INFORMATION_SCHEMA .COLUMNS
        WHERE TABLE_NAME = @tableName
        ORDER BY ORDINAL_POSITION
        ) AS a1
    UNION
    SELECT 3 as rowNr,   '} // class ' + @tableName
    ) as t Order By rowNr asc
END
--调用下面的代码生对指定表的实体类
Helper_CreatePocoFromTableName 'Account'
--调用下面的代码生成所有实体实
USE Linshu
GO
    DECLARE @field1 nvarchar(400 )
    DECLARE cur CURSOR LOCAL for

    SELECT TABLE_NAME FROM information_schema .tables
    OPEN cur
    FETCH NEXT FROM cur INTO @field1 --, @field2
    WHILE @@FETCH_STATUS = 0 BEGIN         
        exec Helper_CreatePocoFromTableName @field1 -- , @field2           
        fetch next from cur into @field1 -- , @field2
    END

close cur
deallocate cur