Sends for the fellow dear visitors:welcome to dongpad!


 Welcome to DongPad!

 msn


| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 预览模式: 普通 | 列表

Isolated Storage in SL4

This Article is Published by Live Writer。

在Silverlight4中,默认应用程序存储配额是1MB=1024KB=1048576Bytes,可以在SL程序的右键菜单点击查看,如下图1:

如果要申请配额,可以在构造里检查存储配额然后执行一下代码,但要考虑到用户可能阻止该请求:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    Int64 IsoQuota = store.Quota; //单位为bytes
    Int64 requestIsoQuota = 1000;
    if (store.IncreaseQuotaTo(IsoQuota +requestIsoQuota )) //增加到指定大小
    {
       //……
    }
}

执行上述代码将自动提示用户"是否要增加可用存储",结果如下图2:

为了保持默认的1MB默认存储,我们选择“否”以便于后面的测试,如果选择了“是”也没关系,我们可以在应用程序存储选项页中选择该程序删除网站对应的存储使其重新初始化到1MB。在上述代码中,我们请求增加的配额为1000bytes,但是提示请求的大小依然是默认的配额1MB,这里Silverlight是如何显示申请存储配额时请求的大小的呢?

经测试发现,Silverlight对请求的大小采用了小数点保留一位四舍五入的策略,上图的请求的大小实际上就是上述代码中(IsoQuota +requestIsoQuota)除以(1MB*1024*1024)四舍五入保留一位小数的结果。在默认配额情况下,如果请求的配额requestIsoQuota 小于0.05MB=52428.8bytes=52429时,提示请求到的存储大小的小数位将被忽略,但这并不影响实际的存储配额,提示请求的大小依然是1.0MB,如果requestIsoQuota大于或等于0.05MB=52428.8bytes(requestIsoQuota类型为Int64,即requestIsoQuota最小为52429时提示请求大小为1.1MB)将提示请求大小为1.1MB。这里我们可以来验证一下,将requestIsoQuota的值更改为52428,提示请求的大小为1.0M,选择“是”对其进行增加可用存储,然后将requestIsoQuota的值更改为1,这时候的提示是请求的大小为1.1M,这也就从侧面反映了显示出来的请求的大小并不影响实际的存储配额,虽然他们可能是不一致的。

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 45 | 返回顶部

Difference between DataContext and ItemsSource in

DataContext is a general (dependency) property of all descendants of FrameworkElement. Is is inherited through the logical tree from parent to children and can be used as an implicit source for DataBinding. It does not do anything by itself, you must basically databind to it.

查看全部...

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 111 | 返回顶部

Sequence Diagram RE, LINQ, and Lambdas

from:Skinner's Blog

本文主要介绍了VS2010特性之Sequence Diagram Reverse Engineering对LINQ和Lambdas的扩展

The Sequence Diagram Reverse Engineering feature available in Visual Studio 2010 allows you to create a UML 2.1 “like” diagram that represents your source code. I say “like” in the previous sentence because we use all the notation prescribed by the UML standard, but there are a few instances where we add some notation that is not found in the standard. Support for LINQ and Lambda expressions are examples of where we have extended the Combined Fragment notation to include what we have dubbed a “Deferred Call”.

Here’s a simple console application that I’ll use to show what I mean.

略……

查看全部...

Tags: DongPad

分类:C# | 固定链接 |评论: 1| 引用: 0 | 查看次数: 187 | 返回顶部

C#编译器(csc.exe)搜索Dll的顺序

This Article is Published by Live Writer。

@CLR via C#2.0 P32
1.工作目录

2.编译器本身目录(PS:根据全局CSC.rsp文件的配置)

3./lib开关指定的目录

4.Lib环境变量指向的工作目录

现在,我们来做了一下尝试,在非编译器目录创建如下两个测试类,并对C1编译:

//C1.cs  @cmd prompt: csc /t:library C1.cs

public class C1
{
public string Name{get;set;}
public int Age{get;set;}
}

//Program.cs   @cmd prompt: csc /r:C1.dll  Program.cs

using System;
public class Program
{
static void Main()
{
C1 c1 = new C1{Name="Jack"};
Console.WriteLine(string.Format("c1's name is {0}",c1.Name));
Console.ReadKey();
}
}

1.编译Program时,由于我们指定的非绝对路径,所以搜索到Program的当前工作目录即结束,我们亦可尝试将C1.Dll剪切到其他工作目录,并指定完整路径进行编译。

2.将C1.dll剪切到csc工作目录C:\Windows\Microsoft.NET\Framework\v3.5(视具体环境而定),编译不通过,what r u doing?

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 224 | 返回顶部

面向对象诠释图

This Article is Published by Live Writer。

from Tyl2008

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 196 | 返回顶部
The problem the user is seeing is that the Thread ctor accepts a specific delegate -- the ThreadStart delegate. The C# compiler will check and make sure your anonymous method matches the signature of the ThreadStart delegate and, if so, produces the proper code under-the-covers to create the ThreadStart delegate for you.
But Control.Invoke is typed as accepting a "Delegate". This means it can accept any delegate-derived type. The example above shows an anonymous method that has a void return type and takes no parameters. It's possible to have a number of delegate-derived types that match that signature (such as MethodInvoker and ThreadStart -- just as an example). Which specific delegate should the C# compiler use? There's no way for it to infer the exact delegate type so the compiler complains with an error.

Tags: System.Delegate

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 258 | 返回顶部

推荐两个免费Visual Studio插件

This Article is Published by Live Writer。

文章原出处http://www.colobu.com,更多插件参见这里

5. Copy As HTML

http://www.lavernockenterprises.co.uk/downloads/copyashtml/copyashtml.aspx

Copy As HTML是一个轻量级的VS插件。你可以利用它在VS中以HTML格式复制你的代码。在复制时它可以保留语法加亮,缩进和背景色,行数等等,方便你复制你的代码到你的博客、文档中。

8. PowerCommands for Visual Studio 2008

http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=PowerCommands&ReleaseId=559

为VS提供了一堆的命令扩展。

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 379 | 返回顶部

A Look Back…

This Article is Published by Live Writer。

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 308 | 返回顶部

Code Contracts from MSDN

Lots of fixes! Our new release, 1.2.21023.14, has been upgraded to work with Visual Studio 2010 Beta 2. (Of course, it also works with Visual Studio 2008, but this is a great time to download the new beta and get started with it.) There are lots of other improvements: be sure to check out the release notes. And keep using the forum to tell us what you think: many of the fixes were in response to your comments.

Code Contracts provide a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of pre-conditions, post-conditions, and object invariants. Contracts act as checked documentation of your external and internal APIs. The contracts are used to improve testing via runtime checking, enable static contract verification, and documentation generation. Code Contracts bring the advantages of design-by-contract programming to all .NET programming languages. We currently provide three tools:

  • Runtime Checking. Our binary rewriter modifies a program by injecting the contracts, which are checked as part of program execution. Rewritten programs improve testability: each contract acts as an oracle, giving a test run a pass/fail indication. Automatic testing tools, such as Pex, take advantage of contracts to generate more meaningful unit tests by filtering out meaningless test arguments that don't satisfy the pre-conditions.
  • Static Checking. Our static checker can decide if there are any contract violations without even running the program! It checks for implicit contracts, such as null dereferences and array bounds, as well as the explicit contracts. (VSTS Edition only.)
  • Documentation Generation. Our documentation generator augments existing XML doc files with contract information. There are also new style sheets that can be used with Sandcastle so that the generated documentation pages have contract sections.

Code Contracts comes in two editions:

  • Code Contracts Standard Edition: This version installs if you have any edition of Visual Studio other than the Express Edition. It includes the stand-alone contract library, the binary rewriter (for runtime checking), the reference assembly generator, and a set of reference assemblies for the .NET Framework.
  • Code Contracts VSTS Edition: This version installs only if you have Visual Studio Team System. It includes the static checker in addition to all of the features in the Code Contracts Standard Edition.


Download Code Contracts Standard Editionor VSTS Edition.


Read the Code Contracts documentation.



forgot to leave the oraginal address:http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 257 | 返回顶部

WCF之消息队列问题

This Article is Published by Live Writer。

1.Q:此计算机上尚未安装消息队列

A:控制面板 --> 添加或删除程序 --> 添加/删除Windows组件 --> 勾选消息队列 --> 点击详细信息,将包括MSMQ HTTP支持在内的子组件都勾选上 -->确定完成。

上述方法主要是针对XP操作系统,更多安装步骤参见:官方的安装“消息队列 (MSMQ)”

2.Q:消息队列服务不可用

A:运行输入services.msc打开服务,找到Message Queuing服务,该服务主要用来为分布式异步消息应用程序提供通信基础结构,启动该服务即可解决消息队列服务不可用的问题。

Tags: DongPad

分类:C# | 固定链接 |评论: 0| 引用: 0 | 查看次数: 365 | 返回顶部
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |