我正在为我的开源项目获得代码签名证书.我有几个问题:
我有一个用C#开发的程序,它目前在Microsoft .NET Framework v4.0上运行.我已升级到Visual Studio 2012,并且还安装了Microsoft .NET Framework v4.5.在我安装.NET Framework v4.0之前,我的程序看起来如何:
现在我升级到.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会导致此问题?
我正在编写一个 C# 程序,它使用System.IO
方法来处理文件和目录。其中一些方法包括Directory.GetDirectories
、Directory.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) 我有两个数组(两个长度相同),我试图迭代两个数组中的每个元素,并测试这些元素(具有相同的索引)是否相等.我想得到相等的数字和不相等的数字.我已经能够使用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) 我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 。
有什么建议么?
我有以下用于计算百分比减少或增加的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吗?
我正在为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) 我正在尝试包含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).
c# ×5
.net ×2
dll ×2
arrays ×1
authenticode ×1
c#-4.0 ×1
c++ ×1
canvas ×1
certificate ×1
code-signing ×1
filesystems ×1
layout ×1
linq ×1
math ×1
nsis ×1
open-source ×1
optimization ×1
php ×1
platform ×1
sqlite ×1
treeview ×1
try-catch ×1
url ×1
validation ×1
winapi ×1
wpf ×1