小编ub3*_*t4r的帖子

为开源项目签名的个人代码

我正在为我的开源项目获得代码签名证书.我有几个问题:

  1. 作为开发开源项目的未注册公司,有没有办法通过验证过程?
  2. 如果我以个人名义注册代码签名证书,是否涉及任何风险(例如,被盗身份和跟踪)?

open-source code-signing certificate authenticode

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

.NET Framework v4.5更改程序布局

我有一个用C#开发的程序,它目前在Microsoft .NET Framework v4.0上运行.我已升级到Visual Studio 2012,并且还安装了Microsoft .NET Framework v4.5.在我安装.NET Framework v4.0之前,我的程序看起来如何:

使用MS .NET Framework v4.0

现在我升级到.NET Framework v4.5,它的外观如下:

使用MS .NET Framework v4.5

注意TreeView现在在右侧而不是左侧?2个控件分别位于工具条容器中的表格中的单独列中.这个问题发生在8月15日发布的最新/稳定版本的.NET Framework v4.5(准确地说是v4.0.30319.17929或v4.5.50709)上.我想知道是什么导致了这个问题,如果有的话一种防止这种情况发生的方法(除了卸载.NET Framework v4.5)?另外,如果使用v4.0编译该程序,为什么v4.5会导致此问题?

.net c# treeview layout

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

最好检查长度是否超过 MAX_PATH 或捕获 PathTooLongException?

我正在编写一个 C# 程序,它使用System.IO方法来处理文件和目录。其中一些方法包括Directory.GetDirectoriesDirectory.GetFiles、 和 ,如果路径太长,Path.GetDirectoryName它们都可能抛出异常。PathTooLongException我的第一个问题是 Microsoft .NET Framework 是否会像在 C++ 中调用 Windows API 一样强制执行路径的最大长度?C# 中的路径(在 a 中string)超出范围是否MAX_PATH会导致PathTooLongException抛出?

我应该用这个吗?

string getFolderName(string path) 
{
    if (string.IsNullOrWhiteSpace(path))
        return string.Empty;

    if (path.Length > 260)
    {
        System.Diagnostics.Debug.WriteLine("Path is too long.");
        return string.Empty;
    }

    string folderName = System.IO.Path.GetDirectoryName(path);

    return folderName;
}
Run Code Online (Sandbox Code Playgroud)

或这个?

string getFolderName(string path) 
{
    if (string.IsNullOrWhiteSpace(path))
        return string.Empty;

    string folderName = string.Empty;

    try {
        folderName = System.IO.Path.GetDirectoryName(path);
    } …
Run Code Online (Sandbox Code Playgroud)

c# filesystems validation try-catch

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

获取相同索引处相同元素的数量

我有两个数组(两个长度相同),我试图迭代两个数组中的每个元素,并测试这些元素(具有相同的索引)是否相等.我想得到相等的数字和不相等的数字.我已经能够使用while循环来完成它,但我想知道是否有更快的System.Linq扩展方式?

这就是我现在所拥有的:

    var list1 = new List<Color>
        {
            Color.Aqua,
            Color.AliceBlue,
            Color.Beige,
            Color.Red,
            Color.Green,
            Color.White
        };


        var list2 = new List<Color>
        {
            Color.Red,
            Color.BurlyWood,
            Color.Beige,
            Color.Azure,
            Color.Green,
            Color.Magenta
        };

        var enumFirst = list1.GetEnumerator();
        var enumSecond = list2.GetEnumerator();

        var equal = 0;
        var notEqual = 0;

        while (enumFirst.MoveNext() && enumSecond.MoveNext())
        {
            var colorFirst = enumFirst.Current;
            var colorSecond = enumSecond.Current;

            if (colorFirst == colorSecond)
                equal++;
            else
                notEqual++;
        }

        Console.WriteLine("Elements that are equal: " + equal);
        Console.WriteLine("Elements that …
Run Code Online (Sandbox Code Playgroud)

c# linq arrays c#-4.0

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

加快在WPF中将对象添加到Canvas的速度

Canvas在WPF中使用了一个绘制许多彩色矩形的方法,但是添加它们时,程序运行速度非常慢。我尝试了不同的选择,例如将它们添加到中,Array然后一次全部添加,并使用a Image而不是Canvas来支付它们,但是它们似乎并没有做什么。我有将代码引导到线程中的图形,但是由于C#规则,我必须在主线程中包含图形部分。我还应该注意,问题出在我的计算机上(它运行的是带有14GB DDR2 RAM的Intel Core i7)。

这是添加矩形的代码。它已运行超过83,000次。

    private void AddBlock(double left, double top, double width, double height, Brush color)
    {
        if (this.Dispatcher.Thread != Thread.CurrentThread)
        {
            this.Dispatcher.Invoke(new Action<double, double, double, double, Brush>(this.AddBlock), left, top, width, height, color);
            return;
        }

        Rectangle rect = new Rectangle() { Width = width, Height = height, Fill = color, SnapsToDevicePixels = true };

        this.canvas.Children.Add(rect);

        Canvas.SetLeft(rect, left);
        Canvas.SetTop(rect, top);
    }
Run Code Online (Sandbox Code Playgroud)

注意:正如我在下面的评论中所述,我希望有一些东西可以让它在单独的线程上运行(即使涉及使用P / Invoke),因为似乎没有可行的解决方案,仅使用C#和WPF 。

有什么建议么?

c# wpf optimization canvas

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

计算百分比变化而不除以零

我有以下用于计算百分比减少或增加的PHP:

function CalculatePercentageIncrease( $nLastMonthPeriod, $nCurrentPeriod ) {
    if ( !is_numeric( $nLastMonthPeriod ) || !is_numeric( $nCurrentPeriod ) )
        return 0;

    if ( $nLastMonthPeriod == 0 )
        return 0;

    $nLastMonthPeriod = intval( $nLastMonthPeriod );
    $nCurrentPeriod = intval( $nCurrentPeriod );

    $nDifference = ( ( ( $nCurrentPeriod - $nLastMonthPeriod ) / $nLastMonthPeriod ) * 100 );

    return round( $nDifference );
}
Run Code Online (Sandbox Code Playgroud)

我想知道的问题是if $nLastMonthPeriod是0并且$nCurrentPeriod是10那么它应该返回100而不是0吗?

php math divide-by-zero

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

InternetCrackUrl没有正确返回lpszHostName

我正在为NSIS(Unicode)开发一个插件,我正在尝试使用InternetCrackUrl()来获取URL的主机名(即:http://www.google.com/test.html - > www.google.com)但是只返回"www.google.com"而不是lpszHostName,它会返回"www.google.com/test.html".

这是我的代码:

void __declspec(dllexport) Example(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) {
    g_hwndParent=hwndParent;

    EXDLL_INIT();

    LPWSTR szURI = new WCHAR[string_size];
    URL_COMPONENTS urlComp;

    // Sets szURI to "http://www.xyz.com/test.html"
    popstring(szURI);

    wstring strUri = szURI;

    ZeroMemory(&urlComp, sizeof(urlComp));
    urlComp.dwStructSize = sizeof(urlComp);

    // Set required component lengths to non-zero so that they are cracked.
    urlComp.dwHostNameLength = static_cast<DWORD>(-1);
    urlComp.dwSchemeLength = static_cast<DWORD>(-1);
    urlComp.dwUrlPathLength = static_cast<DWORD>(-1);
    urlComp.dwExtraInfoLength = static_cast<DWORD>(-1);

    if (!InternetCrackUrlW(strUri.c_str(), strUri.length(), 0, &urlComp)) {
        return _T("InternetCrackUrl failed");
    }

    // …
Run Code Online (Sandbox Code Playgroud)

c++ url dll winapi nsis

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

x86 DLL工作但不是x64 DLL

我正在尝试包含System.Data.SQLite我的项目,该项目使用C#编码并使用.NET Framework v4.我有点困惑......我正在运行Windows 8.1 x64,项目的平台目标设置为Any CPU.如果我包含x64版本,System.Data.SQLite.dll那么我会收到错误消息The type or namespace name 'SQLite' does not exist in the namespace 'System.Data' (are you missing an assembly reference?).但是,如果我包含其x86版本,System.Data.SQLite.dll则编译正常.不应该是相反的方式(不应该x86版本不编译)?由于x86版本可以工作,那么我可以在编译项目中只包含x86版本吗?如果我需要同时包含x86和x64版本System.Data.SQLite.dll(以及SQLite.Interop.dll),那我该怎么做呢?我还应该注意版本System.Data.SQLite是v1.0.94.0(适用于.NET Framework 4).

.net c# sqlite dll platform

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