我有一个内部应用程序,我需要有两个日期类型元素的下拉列表: 月和年.这些值不在数据库或其他信息库中.
我知道我可以通过将它们添加到像对象这样的字典中来设置一个包含我需要的值的列表(我需要将Month与数值表示相关联,January => 01):
var months = new Dictionary<String,String>();
months.Add("01", "January");
...
Run Code Online (Sandbox Code Playgroud)
今年的下拉列表将更容易,因为我可以选择一个起始年份并在通用列表中迭代到当前或当前+ 1年.
有没有更好的方法来处理这些数据元素?内置的东西,或者我应该实现的良好设计模式?
我一直在Windows服务应用程序中组装一个小的嵌入式HTTP服务器,该应用程序监听来自网络上使用HTTP的其他设备的更新.
对于每个HTTP请求,处理请求/响应的代码执行两次,我希望它只运行一次. 我使用AsyncGetContext方法并使用同步版本GetContext尝试了代码 - 最终结果是相同的.
码
public void RunService()
{
var prefix = "http://*:4333/";
HttpListener listener = new HttpListener();
listener.Prefixes.Add(prefix);
try
{
listener.Start();
_logger.Debug(String.Format("Listening on http.sys prefix: {0}", prefix));
}
catch (HttpListenerException hlex)
{
_logger.Error(String.Format("HttpListener failed to start listening. Error Code: {0}", hlex.ErrorCode));
return;
}
while (listener.IsListening)
{
var context = listener.GetContext(); // This line returns a second time through the while loop for each request
ProcessRequest(context);
}
listener.Close();
}
private void ProcessRequest(HttpListenerContext context)
{
// Get the data from …Run Code Online (Sandbox Code Playgroud)