如何在不更改实际时间的情况下将预先存在的日期时间转换为UTC时间.
例:
DateTime dateTime = GetSomeDateTime(); // dateTime here is 3pm
dateTime.ToUtcDateTime() // datetime should still be 3pm
Run Code Online (Sandbox Code Playgroud) 我有一个控制台程序,其中包含不同的组件,如下所示:
void start() {
while(true){
DoSomething();
Thread.Sleep(1000*5);
}
}
Run Code Online (Sandbox Code Playgroud)
我的主要入口点看起来像[伪代码]
Thread.Start(Componenet1.Start);
Thread.Start(Componenet2.Start);
while(true){
Console.Writeline("running");
Thread.Sleep(1000*5);
}
Run Code Online (Sandbox Code Playgroud)
在任何地方都没有Console.Reads.我的问题是SOMETIMES应用程序将运行良好,但然后停止,如果我按下窗口上的任何键它将再次开始工作.这种情况很少发生,但我在100+ VM上部署了这个程序,在自动化环境中全天候运行.
另外在电脑上我有一些AHK脚本和其他操纵鼠标的东西,但不确定它是否与它有任何关系.
另请注意,有时CPU可以在机器上以100%的速度运行,因此可能是线程优先级问题?
SOLUTION:您需要禁用快速编辑模式.这是使用C#代码执行此操作:
// http://msdn.microsoft.com/en-us/library/ms686033(VS.85).aspx
[DllImport("kernel32.dll")]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
private const uint ENABLE_EXTENDED_FLAGS = 0x0080;
static void Main(string[] args)
{
IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
SetConsoleMode(handle, ENABLE_EXTENDED_FLAGS);
Run Code Online (Sandbox Code Playgroud) 我试图让websockets在我的开发环境中工作:
不幸的是,Javscript客户端正在使用长轮询.当我在客户端强制使用Web套接字时,我根本无法连接:
$.connection.hub.start({ transport: ['webSockets'] })
Run Code Online (Sandbox Code Playgroud)
服务器代码是自托管的,基于示例,如下所示:
static void Main(string[] args)
{
string url = "http://localhost:8081/";
var server = new Server(url);
// Map the default hub url (/signalr)
server.MapHubs();
// Start the server
server.Start();
Console.WriteLine("Server running on {0}", url);
// Keep going until somebody hits 'x'
while (true)
{
ConsoleKeyInfo ki = Console.ReadKey(true);
if (ki.Key == ConsoleKey.X)
{
break;
}
}
}
public class MyHub : Hub
{
public void Send(string message) …
Run Code Online (Sandbox Code Playgroud) 由于C#添加了可选参数,因此使用可选参数或方法重载被认为是更好的做法,或者是否存在您希望使用其中一个的特定情况.即具有许多参数的函数更适合w /可选参数?
嘿,你如何获得发出请求的人的IP地址,如下所示:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public partial class UsersService
{
[WebInvoke(UriTemplate = "", Method = "PUT")]
public User AddNewUser(User newUser)
{
// code goes here including GETTING AN IP??
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我需要从磁盘读取1gb原始文本文件到ram以在C#中进行一些字符串操作.
string contents = File.ReadAllText(path)
Run Code Online (Sandbox Code Playgroud)
抛出内存异常(不出所料)
最好的方法是什么?
这是使用反射更新属性的最快方法吗?假设该属性始终为int:
PropertyInfo counterPropertyInfo = GetProperty();
int value = (int)counterPropertyInfo.GetValue(this, null);
counterPropertyInfo.SetValue(this, value + 1, null);
Run Code Online (Sandbox Code Playgroud) 我有几个不同的代码,但简短的故事是我使用SHA1将一些密码插入到MySQL数据库中,并且还将SHA1哈希计算到.NET中并且它们不匹配.我认为这是我的.NET编码代码的问题.
SQL代码:
INSERT INTO user_credentials (Password) VALUES (SHA1('password'));
Run Code Online (Sandbox Code Playgroud)
密码哈希为5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
.NET代码:
public static string GetPasswordHash(string password)
{
// problem here with encoding?
byte[] byteArray = Encoding.ASCII.GetBytes(password);
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] hashedPasswordBytes = sha.ComputeHash(byteArray);
return Encoding.ASCII.GetString(hashedPasswordBytes);
}
Run Code Online (Sandbox Code Playgroud)
密码哈希到[?a ??????%l?3~ ???
谢谢你的帮助!
可能重复:
调用的=>标记是什么?
嘿,
在LINQ中,=>运算符的名称是什么,例如:
list.Where(a => a.value == 5);
Run Code Online (Sandbox Code Playgroud) 请注意,这是针对MVC 4中的ApiController,尽管我认为它不应该改变任何东西.
public class OAuthFilter : System.Web.Http.ActionFilterAttribute
{
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (checkVerified())
{
// How to raise a 401 or some other type of exception.
}
}
}
Run Code Online (Sandbox Code Playgroud) c# ×10
asp.net ×1
automation ×1
coding-style ×1
cryptographic-hash-function ×1
cryptography ×1
datetime ×1
file-io ×1
linq ×1
mysql ×1
overloading ×1
performance ×1
properties ×1
reflection ×1
rest ×1
sha1 ×1
signalr ×1
string ×1
tcp ×1
utc ×1
wcf ×1