小编Tom*_*len的帖子

垃圾收集,我们应该依赖它吗?

在代码中,我们说:

using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString()))
{
    cn.Open();

    // Set all previous settings to inactive
    using (SqlCommand cmd = new SqlCommand("UPDATE tblSiteSettings SET isActive = 0", cn))
    {                            
        cmd.ExecuteNonQuery();
    }

    cn.Close();
}
Run Code Online (Sandbox Code Playgroud)

cn.close在技​​术上是不必要的,因为垃圾收集将为我们处理连接.

但是,我总是喜欢关闭它,不依赖于垃圾收集.这不好吗?浪费时间?或者考虑不依赖自动化的良好做法?

提前感谢您的想法和意见.我将此标记为社区维基,因为它可能是主观的.

c# garbage-collection

6
推荐指数
2
解决办法
682
查看次数

如何压缩CSS

我已经看了六个CSS优化器.我正在寻找的是一个将转向:

background-image: url(../images/background.png);
background-repeat: repeat-x;
background-color: #c0c0c0;
Run Code Online (Sandbox Code Playgroud)

进入单个背景属性:

background: #c0c0c0 url(../images/background.png) repeat-x;
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我必须手工完成吗?

css optimization

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

C#获取所有可用的FontFamily

我有一个输入框,人们输入一个字体,它保存了他们键入的JPEG格式.一切正常.但是,当他们键入一个字体名称,如' times new roman'它必须正确地大写' Times New Roman'或它不会工作!

我可以以某种方式迭代所有可用的字体并将其作为下拉列表呈现给它们,这样就没有拼写问题,它们肯定只会在系统上使用字体吗?

c# fonts loops font-face font-family

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

LINQ冲突 - 未找到或更改行

我从用户那里得到了相当频繁的错误报告,典型的一个是:

Error Message: Row not found or changed.
Stack Trace:
at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) 
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) 
at Controls_Article_ArticleViewer.LoadArticle() 
at ViewTutorial.Page_Load(Object sender, EventArgs e) 
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) 
at System.Web.UI.Control.LoadRecursive() 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Run Code Online (Sandbox Code Playgroud)

(如果需要,我可以提供更多细节).该函数中唯一直接的LINQ代码LoadArticle()是:

    using (MainContext db = new MainContext())
    {
        var q = (
                    from A in db.tblArticles
                    where A.ID == this.ArticleID && A.IsDeleted == false
                    select A
                ).SingleOrDefault();
        if (q == null)
        {
            Server.Transfer("~/404.aspx");
            Context.Response.End();
        }
        else
        {
            // Cache …
Run Code Online (Sandbox Code Playgroud)

c# linq asp.net conflict

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

Linq返回字符串数组

/// <summary>
/// Returns list of popular searches
/// </summary>
public static string[] getPopularSearches(int SectionID, int MaxToFetch)
{
    using (MainContext db = new MainContext())
    {
        return (from c in db.tblSearches where c.SectionID == SectionID && c.Featured select new[] { c.Term });
    }
}
Run Code Online (Sandbox Code Playgroud)

我看了其他问题,但它们似乎略有不同,我得到了错误:

Cannot implicitly convert type 'System.Linq.IQueryable<string[]>' to 'string[]'
Run Code Online (Sandbox Code Playgroud)

我知道这可能很简单,有人可以指出这里有什么问题吗?

c# linq asp.net arrays string

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

XMLHTTP请求的经典ASP错误

我在IIS 7.5上运行经典ASP和ASP.net 4.0.

在我的经典ASP代码是这段代码:

' Process @ alerts
Dim objHttp
set objHttp = Server.CreateObject("Microsoft.XMLHTTP")

objHttp.open "POST", strSiteRoot & "handlers/forumalerts.ashx?", false
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHttp.Send "topicID=" & lngTopicID & "&threadID=" & lngLastPostID

set objHttp = nothing
Run Code Online (Sandbox Code Playgroud)

这是向ASP.net ASHX处理程序发送请求.运行时,它会在最终发送错误消息之前挂起很长时间:

msxml3.dll错误'800c0008'

指定资源的下载失败.

/forum/new_post.asp,第1036行

我已经检查了它发布到的URL,它存在且正在运行.发送的数据也是正确的.

在我全新安装Windows 7之前,它运行良好.由于重新安装它,并再次设置IIS这段代码失败,让我相信它是一个权限/身份错误.

有谁能告诉我是什么原因造成的?我有3个应用程序池:

ASP.net v4.0 (Integrated) (ApplicationPoolIdentity)
ASP.net v4.0 Classic (Classic) (ApplicationPoolIdentity)
DefaultAppPool (Integrated) (NetworkService)
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

编辑:我在日志中发现了这个错误:

Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 02/11/2011 14:55:42 
Event time (UTC): 02/11/2011 14:55:42 
Event ID: 4e550d910b934d2781707701f833e18e …
Run Code Online (Sandbox Code Playgroud)

asp.net iis-7 xmlhttprequest asp-classic

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

Jquery停止HTML编码cookie

我正在使用这段简短的代码:

var d = itemID + "," + quantity;
var CookieData = $.cookie("storebasket");

if(CookieData == null || CookieData == "") {
    $.cookie("storebasket", d, { path: '/', expires: 60 });
} else {
    $.cookie("storebasket", CookieData + "|" + d, { path: '/', expires: 60 });
}
Run Code Online (Sandbox Code Playgroud)

但是,值ALWAYS将变为HTML编码.例如:

5%2C1
Run Code Online (Sandbox Code Playgroud)

使用此工具解码:

5,1
Run Code Online (Sandbox Code Playgroud)

我尝试过unescape但没有运气:

$.cookie("storebasket", unescape(d), { path: '/', expires: 60 });
Run Code Online (Sandbox Code Playgroud)

还有什么想法吗?

cookies jquery html-encode escaping

6
推荐指数
2
解决办法
4789
查看次数

Google图表显示Money not Percentages

给出饼图的数据:

data = new google.visualization.arrayToDataTable([
    ['Sales', 'Revenue Distribution'],
    ['Author', 5],
    ['Company', 2],
    ['Tax', 0.4],
    ['Payment Processors', 0.9]
]);
drawChart();
Run Code Online (Sandbox Code Playgroud)

如何将其显示为美元金额?无论是在工具提示中还是在实际图形本身上(两者都更可取!)

例如,理想情况下这可以工作:

data = new google.visualization.arrayToDataTable([
    ['Sales', 'Revenue Distribution'],
    ['Author', '$5'],
    ['Company', '$2'],
    ['Tax', '$0.4'],
    ['Payment Processors', '$0.9']
]);
drawChart();
Run Code Online (Sandbox Code Playgroud)

javascript formatting google-visualization

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

从整数集创建字节数组

鉴于这些整数:

public uint ServerSequenceNumber;
public uint Reserved1;
public uint Reserved2;
public byte Reserved3;
public byte TotalPlayers;
Run Code Online (Sandbox Code Playgroud)

byte[]从它们创建数组的最佳方法是什么?如果它们的所有值都是1结果数组将是:

00000000000000000000000000000001 00000000000000000000000000000001 00000000000000000000000000000001 00000001 00000001
Run Code Online (Sandbox Code Playgroud)

c# byte bit-manipulation bytearray concatenation

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

无法在“窗口”上执行“postMessage”:目标来源无效

我有 iframe:

<iframe id="GameFrame" 
sandbox="allow-scripts allow-pointer-lock" 
src="https://127.0.0.1:112/games/1047/play">
</iframe>
Run Code Online (Sandbox Code Playgroud)

我的父页面位于:

https://127.0.0.1/arcade/not-hidden/space-blaster-1047
Run Code Online (Sandbox Code Playgroud)

我正在尝试向 iFrame 发布消息:

var gameIframe = $("#GameFrame");
gameIframe.get(0).contentWindow.postMessage("screenshot", "");
Run Code Online (Sandbox Code Playgroud)

但这会引发错误:

未捕获的语法错误:无法在“窗口”上执行“postMessage”:在调用“postMessage”时目标源“无效”。

其他尝试:

postMessage("screenshot", "https://127.0.0.1");
Run Code Online (Sandbox Code Playgroud)

无法在“DOMWindow”上执行“postMessage”:提供的目标源(“ https://127.0.0.1 ”)与收件人窗口的源(“null”)不匹配。

我怎样才能得到这个发布到 iFrame 的消息?

html iframe postmessage sandbox

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