我正在开发一个可本地化的应用程序.在我的"本地"资源文件中,我使用默认语言(英语),如果可能的话,我加载用户的首选项和文化,并加载翻译成语言的字符串.
所以我做了什么:
private static CultureInfo _culture = CultureInfo.CurrentUICulture;
private static ResourceManager _manager;
private static void ToNeutralCulture()
{
while (!_culture.IsNeutralCulture)
{
_culture = _culture.Parent;
}
}
private static void LoadCulture()
{
ResourceManager manager = Properties.Resources.ResourceManager;
try
{
ToNeutralCulture();
string assembly = Assembly.GetCallingAssembly().GetName().CodeBase;
string assemblyDir = Path.GetDirectoryName(assembly);
string assemblyName = Path.GetFileNameWithoutExtension(assembly);
string resourceFileName = string.Format(CultureInfo.InvariantCulture,
@"{0}\{1}_{2}.dll",
assemblyDir,
assemblyName,
_culture.Name.ToUpper());
FileInfo resourceFile = new FileInfo(resourceFileName);
if (resourceFile.Exists)
{
Assembly resourceAssembly = Assembly.LoadFrom(resourceFile.FullName);
string[] manifests = resourceAssembly.GetManifestResourceNames();
if (manifests.Length == 1)
{
manager = …Run Code Online (Sandbox Code Playgroud) 我有一个需要在Compact .NET Framework 3.5和.NET Framework 3.5中编译的项目(实际上只有2个项目,只编译两者之间发生变化的选项).
问题是,CF .NET中缺少某些类,所以我手动创建它(并实现了.NET中可用的所有类成员)
一个例子:FtpWebRequest/FtpWebResponse类.
写这样的东西是不好的(如果是,为什么?):
#if CFNET35 // Only if we are in Compact Framework 3.5 mode
namespace System.Net
{
public class FtpWebRequest : WebRequest
{
// ...
}
public class FtpWebResponse : WebResponse
{
// ...
}
}
#endif
Run Code Online (Sandbox Code Playgroud)
我敢肯定,在CF.NET35中,这些方法永远不可用,我可以编写它吗?
我会写这个是为了避免在项目中使用我的库时发生名称冲突.
它允许我在其他项目中总是白using System.Net;求问我使用哪个框架...
谢谢 !
几个月后,我会评估我使用的策略.
如上所述,我通过进行条件编译来覆盖System(.Net)命名空间,所以我有两个DLL(一个用于CF.NET,一个用于.NET)
这也包括我使用这个DLL的所有应用程序都是双重的(每次都是CF.NET应用程序和一个包含相应库的.NET应用程序).
所以,这是一个坏主意,我有很多项目是双重的,而且.NET应用程序可以直接包含和使用CF.NET库的方式是不必要的.
此外,我还没有注意的是,如果一个.NET应用程序包含一个带有覆盖系统命名空间的CF.NET库,由于类名冲突,它的初始化将失败...
因此,提供通用接口的EPIC FAIL是管理此案例的最佳方式.
我正在研究CF.NET的一个小技术框架,我的问题是,我应该如何编写异步部分?在MSDN上阅读很多内容但对我来说并不清楚.
所以,这是代码:
public class A
{
public IAsyncResult BeginExecute(AsyncCallback callback)
{
// What should I put here ?
}
public void EndExecute()
{
// What should I put here ?
}
public void Execute()
{
Thread.Sleep(1000 * 10);
}
}
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我......
谢谢 !
我目前正在审查一个C#应用程序,我在其中看到:
public static bool ServiceExists(string servicename)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController s in services)
{
if (s.ServiceName == servicename)
{
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
在这个答案中,Henk表示不使用Dispose()(或using)不会产生内存泄漏,无论是真是假?
我可以保留以前的代码吗或者我应该写一些像:
public static bool ServiceExists(string servicename)
{
ServiceController[] services = ServiceController.GetServices();
bool exists = false;
foreach (ServiceController s in services)
{
using(s)
{
if (s.ServiceName == servicename)
{
exists = true;
}
}
}
return exists;
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,不使用Dispose()(或using)有什么风险?
只是要知道,是否可以安全地通过Ajax请求发送密码?
我有一个登录框调用ajax请求来尝试登录/传递并检索有错误的JSON对象(如果有的话).
我应该使用表单重定向吗?
[编辑]将加密密码存储在数据库中不是解决方案,因为ajax发送的登录名和密码是访问数据库本身的登录名/密码(内部应用程序).
我正在维护一个现有的应用程序,并且在某些情况下运行时遇到了一个错误(很容易重现),其中app失败并显示消息:
问题是:我需要先检查一下?这个消息什么时候发生?为什么?
在C#中存储在这个虚拟内存中的原因是什么?
我有一个由JS脚本填满的网页,它创建了很多HTML表格.
<table>创建的数量可以在1到1000之间变化,每个单元中有100个单元格.
我的问题是:如何有效地绑定这些表上的点击?我应该将单击的每个单元格<table>或直接绑定到<table>自身并检索单击绑定功能中的单元格吗?
或者你有另一个想法?
谢谢
PS:我正在使用IE6 +
我观察到一种非常奇怪的行为,也许你可以帮助我看看会发生什么.
这里的课程:
public sealed class Sudoku
{
private SudokuCell[] _grid = new SudokuCell[81];
// ctor {}
private IEnumerable<SudokuCell> Grid
{
get { return _grid; }
}
private SudokuRow[] _rows;
public IEnumerable<SudokuRow> Rows
{
get
{
if (_rows == null)
{
_rows = new SudokuRow[9];
for (int i = 0, length = 9; i < length; i++)
{
_rows[i] = new SudokuRow(from cell in Grid
where cell.Row == i
select cell);
// Always print 9 (GOOD)
Trace.WriteLine("First Loop " + i …Run Code Online (Sandbox Code Playgroud) 以下是我更改TimeZoneInfo(App#1)的方法:
private static void ChangeTimeZone(TimeZoneInfo tzi)
{
TIME_ZONE_INFORMATION actual = new TIME_ZONE_INFORMATION();
NativeMethods.GetTimeZoneInformation(out actual);
if (tzi == null || actual.StandardName == tzi.StandardName)
return;
TIME_ZONE_INFORMATION newZone = (TIME_ZONE_INFORMATION)tzi;
RunWin32Method(() => NativeMethods.SetTimeZoneInformation(ref newZone));
// Update .NET
CultureInfo.CurrentCulture.ClearCachedData();
TimeZoneInfo.ClearCachedData();
// Notify all windows that we changed a Windows setting.
// result is True
IntPtr ptr;
System.Diagnostics.Debug.WriteLine(NativeMethods.SendMessageTimeout(NativeMethods.HWND_BROADCAST, NativeMethods.WMI_SETTING_CHANGE,
IntPtr.Zero, IntPtr.Zero, 0x00, 1000, out ptr));
}
Run Code Online (Sandbox Code Playgroud)
当我打电话给我的方法:
ChangeTimeZone(TimeZoneInfo.GetSystemTimeZones().First(e => !e.SupportsDaylightSavingTime));
// Stopping debugger and watching other .NET App then continue to next instruction
ChangeTimeZone(TimeZoneInfo.GetSystemTimeZones().First(e => …Run Code Online (Sandbox Code Playgroud) 有两个流,第一个显示进程表,第二个流则考虑计数和显示.最初是为第一个推出,然后是第二个:
Thread t1 = new Thread(tmh1.FillTable);
Thread t2 = new Thread(tmh1.GetGeneralInfo);
t1.Start();
t2.Start();
Run Code Online (Sandbox Code Playgroud)
以下是在线程中运行的方法:
public void FillTable()
{
while (true)
{
lock (lockObj)
{
arr.Clear();
arr.AddRange(Process.GetProcesses());
TableFormatter.Line();
TableFormatter.Row("Name", "ID", "threads quantity", "Start time");
TableFormatter.Line();
}
Thread.Sleep(interval);
}
}
public void GetGeneralInfo()
{
while (true)
{
lock (lockObj)
{
Console.WriteLine(arr.Count.ToString());
}
Thread.Sleep(interval);
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
0
-----------------------------------------------------------------------------
| Name | ID | threads quantity| Start time |
-----------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
但应该如下:
-----------------------------------------------------------------------------
| Name | ID | threads quantity| Start time |
----------------------------------------------------------------------------- …Run Code Online (Sandbox Code Playgroud) c# ×8
javascript ×2
.net ×1
ajax ×1
arrays ×1
assemblies ×1
asynchronous ×1
frameworks ×1
idisposable ×1
jquery ×1
linq ×1
locking ×1
memory-leaks ×1
namespaces ×1
passwords ×1
pinvoke ×1
resources ×1