不同的操作系统,桌面的路径不尽相同,而且随着用户安装位置的不同也不同。
C#可以从Windows注册表读取得到用户的特殊文件夹(桌面、收藏夹等等)的位置。
代码如下:
[code=’c#’]
using Microsoft.Win32;
namespace JPGCompact
{
public partial class MainForm : Form
{
private void Test()
{
RegistryKey folders;
folders = OpenRegistryPath(Registry.CurrentUser, @”\software\microsoft\windows\currentversion\explorer\shell folders”);
// Windows用户桌面路径
string desktopPath = folders.GetValue(“Desktop”).ToString();
// Windows用户字体目录路径
string fontsPath = folders.GetValue(“Fonts”).ToString();
// Windows用户网络邻居路径
string nethoodPath = folders.GetValue(“Nethood”).ToString();
// Windows用户我的文档路径
string personalPath = folders.GetValue(“Personal”).ToString();
// Windows用户开始菜单程序路径
string programsPath = folders.GetValue(“Programs”).ToString();
// Windows用户存放用户最近访问文档快捷方式的目录路径
string recentPath = folders.GetValue(“Recent”).ToString();
// Windows用户发送到目录路径
string sendtoPath = folders.GetValue(“Sendto”).ToString();
// Windows用户开始菜单目录路径
string startmenuPath = folders.GetValue(“Startmenu”).ToString();
// Windows用户开始菜单启动项目录路径
string startupPath = folders.GetValue(“Startup”).ToString();
// Windows用户收藏夹目录路径
string favoritesPath = folders.GetValue(“Favorites”).ToString();
// Windows用户网页历史目录路径
string historyPath = folders.GetValue(“History”).ToString();
// Windows用户Cookies目录路径
string cookiesPath = folders.GetValue(“Cookies”).ToString();
// Windows用户Cache目录路径
string cachePath = folders.GetValue(“Cache”).ToString();
// Windows用户应用程式数据目录路径
string appdataPath = folders.GetValue(“Appdata”).ToString();
// Windows用户打印目录路径
string printhoodPath = folders.GetValue(“Printhood”).ToString();
}

private RegistryKey OpenRegistryPath(RegistryKey root, string s)
{
s = s.Remove(0, 1) + @”\”;
while (s.IndexOf(@”\”) != -1)
{
root = root.OpenSubKey(s.Substring(0, s.IndexOf(@”\”)));
s = s.Remove(0, s.IndexOf(@”\”) + 1);
}
return root;
}
}
}
[/code]

Effictive C#, 50 Specific Ways to Improve Your C#一书提到,运行时常量readonly比编译时常量const更好。不是因为运行时常量readonly会比较快,而是因为这样的常量是运行时查找位置的,而不是编译时直接编译进IL,因此当版本出现交差覆盖的时候不会出错,也许会慢一点点,但是运行时常量readonly总是能够正确运行。
那么,运行时常量readonly到底比编译时常量const慢多少呢?
我写了个测试,框架就不介绍了。

[code=’c#’]
using System;
using System.Collections.Generic;
using System.Text;

namespace CSharpPerformance.TestCase
{
class ReadOnlyVsConst : TestCase
{
private const double ConstValue = 1.23456789;
private readonly double ReadOnlyValue = 1.23456789;

private double DoCalculate(double value, long count)
{
double result = 1;
for (int i = 0; i < count; i++) { result *= value; } return result; } public override void DoTest() { int count = 100000000; name1 = "Const: "; DateTime start = DateTime.Now; DoCalculate(ConstValue, count); DateTime end = DateTime.Now; span1 = end.Subtract(start); name2 = "ReadOnly: "; start = DateTime.Now; DoCalculate(ReadOnlyValue, count); end = DateTime.Now; span2 = end.Subtract(start); } } } [/code] 我执行了10遍,结果是这样的: Debug模式(Optimize code: ON):
[code=’c#’]
Const: 00:00:12.5802579
ReadOnly: 00:00:13.6913690
————————————
Const: 00:00:13.2063205
ReadOnly: 00:00:12.7162715
————————————
Const: 00:00:12.5372536
ReadOnly: 00:00:12.2612260
————————————
Const: 00:00:12.3152314
ReadOnly: 00:00:12.4542453
————————————
Const: 00:00:12.4342433
ReadOnly: 00:00:12.5922591
————————————
Const: 00:00:12.3752374
ReadOnly: 00:00:12.3442343
————————————
Const: 00:00:12.1912190
ReadOnly: 00:00:12.1782177
————————————
Const: 00:00:12.1932192
ReadOnly: 00:00:12.2582257
————————————
Const: 00:00:12.2472246
ReadOnly: 00:00:12.2532252
————————————
Const: 00:00:12.2462245
ReadOnly: 00:00:12.3122311
————————————
[/code]
结果:const VS readonly:6:4

Debug模式(Optimize code: OFF):
[code=’c#’]
Const: 00:00:12.4402439
ReadOnly: 00:00:12.3002299
————————————
Const: 00:00:12.2512250
ReadOnly: 00:00:12.2272226
————————————
Const: 00:00:12.2302229
ReadOnly: 00:00:12.1962195
————————————
Const: 00:00:12.2922291
ReadOnly: 00:00:12.2152214
————————————
Const: 00:00:12.3062305
ReadOnly: 00:00:12.1942193
————————————
Const: 00:00:12.2012200
ReadOnly: 00:00:12.2252224
————————————
Const: 00:00:12.1922191
ReadOnly: 00:00:12.2402239
————————————
Const: 00:00:12.2602259
ReadOnly: 00:00:12.2452244
————————————
Const: 00:00:12.2322231
ReadOnly: 00:00:12.1952194
————————————
Const: 00:00:12.2492248
ReadOnly: 00:00:12.1912190
————————————
[/code]
结果:const VS readonly:2:8,Shocking!

Release模式(Optimize code: ON):
[code=’c#’]
Const: 00:00:08.7728772
ReadOnly: 00:00:08.8708870
————————————
Const: 00:00:08.7698769
ReadOnly: 00:00:08.7088708
————————————
Const: 00:00:08.7148714
ReadOnly: 00:00:08.6878687
————————————
Const: 00:00:08.7258725
ReadOnly: 00:00:08.7758775
————————————
Const: 00:00:08.8258825
ReadOnly: 00:00:08.7748774
————————————
Const: 00:00:08.8948894
ReadOnly: 00:00:08.8378837
————————————
Const: 00:00:08.7198719
ReadOnly: 00:00:08.8348834
————————————
Const: 00:00:08.7338733
ReadOnly: 00:00:08.7398739
————————————
Const: 00:00:08.7138713
ReadOnly: 00:00:08.7688768
————————————
Const: 00:00:08.7948794
ReadOnly: 00:00:08.7698769
————————————
[/code]
结果:const VS readonly:5:5

Release模式(Optimize code: OFF):
[code=’c#’]
Const: 00:00:08.9068906
ReadOnly: 00:00:08.9008900
————————————
Const: 00:00:08.9108910
ReadOnly: 00:00:08.7988798
————————————
Const: 00:00:08.8098809
ReadOnly: 00:00:08.7978797
————————————
Const: 00:00:08.8048804
ReadOnly: 00:00:08.8218821
————————————
Const: 00:00:08.9528952
ReadOnly: 00:00:08.8898889
————————————
Const: 00:00:08.9138913
ReadOnly: 00:00:09.0019001
————————————
Const: 00:00:08.9288928
ReadOnly: 00:00:08.7968796
————————————
Const: 00:00:08.7798779
ReadOnly: 00:00:08.8298829
————————————
Const: 00:00:08.8258825
ReadOnly: 00:00:08.7558755
————————————
Const: 00:00:08.8138813
ReadOnly: 00:00:08.8168816
————————————
[/code]
结果:const VS readonly:4:6

数数看,理论上const应该是绝对快的,其实不然。编译优化关闭的时候,const居然落后于readonly。

这里有三张照片,控制住自己,别拉得太快,猜猜看这是做什么用的?
提示一下,Bosch的GBL 550,价值人民币800元。

[singlepic=15820,630,410]

[singlepic=15819,630,410]

[singlepic=15821,630,410]

答案是,给服务器吹灰专用的吹风筒。

SMS.cs,一个订阅者
[sourcecode language=’c#’]
using System;
using System.Collections.Generic;
using System.Text;

namespace EventExample
{
class SMS
{
public void OnNewMail(object sender, NewMailEventArgs e)
{
Console.WriteLine(
“SMS Arrives: [NEW MAIL] {0} to {1}, {2}”,
e.From, e.To, e.Subject);
}
}
}
[/sourcecode]

Phone.cs,另一个订阅者
[sourcecode language=’c#’]
using System;
using System.Collections.Generic;
using System.Text;

namespace EventExample
{
class Phone
{
public void OnNewMail(object sender, NewMailEventArgs e)
{
Console.WriteLine(
“Phone Rings: [NEW MAIL] {0} to {1}, {2}”,
e.From, e.To, e.Subject);
}
}
}
[/sourcecode]

NewMailEventArgs.cs,自定义的事件附加信息类
[sourcecode language=’c#’]
using System;
using System.Collections.Generic;
using System.Text;

namespace EventExample
{
class NewMailEventArgs : EventArgs
{
private readonly string m_from, m_to, m_subject;

public NewMailEventArgs(string from, string to, string subject)
{
this.m_from = from;
this.m_to = to;
this.m_subject = subject;
}

public string From { get { return m_from; } }
public string To { get { return m_to; } }
public string Subject { get { return m_subject; } }
}
}
[/sourcecode]

MailManager.cs,引发事件的类
[sourcecode language=’c#’]
using System;
using System.Collections.Generic;
using System.Text;

namespace EventExample
{
class MailManager
{
public event EventHandler NewMail;

protected virtual void OnNewMail(NewMailEventArgs e)
{
// For thread safe
EventHandler temp = NewMail;

if (temp != null)
{
temp(this, e);
}
}

public void SimulateNewMail(string from, string to, string subject)
{
NewMailEventArgs e = new NewMailEventArgs(from, to, subject);
OnNewMail(e);
}
}
}
[/sourcecode]

这里的类使用了一个线程安全的做法,使用了一个OnNewMail虚方法调用事件,在调用之前首先将事件保存到一个temp中,这是因为确保事件不是null,如果直接判断NewMail是不是null,可能会在判断完之后,当时不是null,而紧接着被另一个线程修改成null,从而导致NullReferenceException的情况。

Program.cs
[sourcecode language=’c#’]
using System;
using System.Collections.Generic;
using System.Text;

namespace EventExample
{
class Program
{
static void Main(string[] args)
{
Phone phone = new Phone();
SMS sms = new SMS();
MailManager mailManager = new MailManager();

mailManager.NewMail += phone.OnNewMail;
mailManager.NewMail += sms.OnNewMail;

for (int i = 0; i < 100; i++) { mailManager.SimulateNewMail( "Someone", "Someone else", "Test Mail" + i.ToString()); } } } } [/sourcecode]

今天我的DreamHost上自动更新的WordPress更新到了一个阶段性的版本,版本号是WordPress 2.7-hemorrhage(revision 8700)。
功能上,一些插件的显示有严重的问题,是找不到入口,即便入口看到也进不去,只好通过地址方式访问。等下一版本更新吧。主要变化是出现了”Utilities”菜单,重新组织了位置,多了”Inbox”。
主要的区别是后台有了不小的变化,如图所示,与2.6不小的变化:

[singlepic=15818,700,484]

主要是错误还比较多,带来不小麻烦。此外,明显感觉出这个后台组织是为宽屏用户考虑的,屏幕宽些才舒服。

Update: revision 8705解决了插件找不到入口的问题…

游戏背景为苏维埃阵营试图回溯过去以期改变第三次世界大战的进程。这场大战在三方之间展开:苏方、盟方、东方神起帝国(Empire of the Rising Sun),玩家将在战场上与熟悉的电塔、空艇、变形坦克重逢。“红警系列游戏向来以其富有内涵的、变化多端及花样翻新的玩法面向富有挑战精神的核心向策略游戏玩家,但它也属于那种能用丰富的故事情节、即刻上手的运作机制,和趣味第一的设计来吸引更多休闲玩家的少数异类”。
本作预计10月28日发售,登陆平台:PC、XBOX360。

游戏配置要求:

  • OS – Windows XP / Vista (32-Bit)
  • 处理器 – XP: 2.0 GHz (Intel Pentium 4; AMD Athlon 2000+; Multiple Cores) / Vista: 2.2 GHz (Intel Pentium 4/AMD Athlon 2200+/Multiple Cores)
  • 内存 – XP/Vista: 1 GB
  • 硬盘 – Media: 6.0 GB / EA Link: 12.0 GB
  • 光驱 – 8 SPEED
  • 显卡 – NVIDIA GeForce 6800, ATI Radeon X1800 or higher end DirectX 9.0c compatible gfx card
  • 声卡 – DirectX 9.0c compatible (Creative Sound Blaster Audigy cards require a Intel P4 2.6 GHz or similar under Vista, Yamaha Xwave-512 not supported)
  • 多人游戏 – 512 Kbps or faster; 2-8 Players
  • 输入 – Keyboard, Mouse
  • 可选 – VoIP Headset

原文链接+视频:
http://www.lingaoyi.com/video/command-conquer-red-alert-3-pc-gc08-fmv-trailer/

[singlepic=15817]

光路图如上所示。
由于L1 = L2 = L3,故当被摄物合焦时,可以在对焦屏、CMOS感光元件和AF感测器三处都合焦。因此只要AF感测器认为已经合焦,取景器里看到的和最终拍下的照片上都是精确合焦的。
AF感测器可以通过多种方式确定是否合焦,分主动式和被动式两种。

  • 主动式是AF感测器通过发射红外线、超声波或激光,然后接受反光。优点是可以用于细线条物体和动体,也可以在低反差,弱光下对焦。
  • 被动式通过接受景物自身的反光实现对焦。优点是不要发射系统,耗能小,易小型化。可以在逆光下或透过玻璃对焦。