这可能只是一个理论问题,但我无法找到令人满意的答案.
我正在我的一个网站上使用缓存,让我思考它的数据以及何时以及是否发生变化.在执行某些代码期间缓存是否会发生变化?
这是一个例子
if (Cache["name"] != null) {
// Long and heavy code execution done here
if (Cache["name"] == null) Response.Write("Lost the data");
}
Run Code Online (Sandbox Code Playgroud)
更改缓存的进程是否可以与上面的代码并行运行,还是等到它完成后?
理论上是否存在打印"丢失数据"的可能性?
如果是的话,首先保存变量或始终检查null并且永远不会为空是否总是好的做法?
提前致谢!
/尼克拉斯
我在旧的惯例中找到了自己,像我一直在做的那样构建网页.只是包含一堆修补程序来修复不同浏览器之间的不一致.所以我想知道......
是否有基本的构建块,例程或设置列表,使每个浏览器中的HTML和CSS看起来都一样?
如果我可以从这个干净的构建块开始,我知道在所有浏览器中看起来都是一样的,我以后可能会修补不同的浏览器不一致性.
但要知道网站的基础适合所有浏览器,难道不是一种好感觉吗?
我想为模型中的某个字段指定一个"标签",并在我的应用程序中的每个位置使用它.
<div class="editor-field">
<%: Html.TextBoxFor(model => model.surname) %>
<%: Html.ValidationMessageFor(model => model.surname) %>
</div>
Run Code Online (Sandbox Code Playgroud)
对此,我想添加如下内容:
<%: Html.LabelFor(model => model.surname) %>
Run Code Online (Sandbox Code Playgroud)
但是标签已存在并写出"姓".但是我想指出它应该显示什么,比如"你的姓".
我确定这很容易= /
在我的表单中,我将类别从一个列表框移动到另一个列表框,如下所示:
底部框是"输入"框,在发布表单时在服务器端读取.这是我创建列表框的方式:
<%: Html.ListBoxFor(m => m.categories, Model.categories)%>
Run Code Online (Sandbox Code Playgroud)
我在这里遇到两个问题:
在Firefox中,当第一次加载表单时,底部框始终具有默认值<option></option>
.是否可以在服务器端删除它?IE似乎创建一个空盒子而不是FF.
为了解决这个问题,我正在删除页面加载时的空选项.这样做的一个问题是,当表单出现错误但未提交时,将再次删除选项.
为了发布底部框中的选项,必须选择它们.为了解决这个问题,我使用下面的jQuery来选择表单上的选项.
jQuery在提交时选择选项:
$("form").submit(function (event) {
$("#categories").find("option").attr('selected', 'selected');
});
Run Code Online (Sandbox Code Playgroud)
jQuery删除加载选项:
$("#categories").find("option").remove();
Run Code Online (Sandbox Code Playgroud)
问题
1.我可以创建一个适用于所有浏览器的空列表框吗?
2.我是否必须选择底部框中的选项或是否有解决方法?
Clarifiation:我希望尽可能多地在服务器端完成,最好是与MVC相关的东西.
我有一个快速的问题,因为我的大脑不会与我合作...我
在哪里指定我希望"用户"中的user_id 不在"群组"中?
db.Users.Join(db.Groups, a => a.user_id, b => b.user_id, (a, b) => new SelectListItem
{
Value = a.user_id.ToString(),
Text = a.surname + " " + a.lastname
});
Run Code Online (Sandbox Code Playgroud) 我在C++中创建一个简单的线程服务器应用程序,事实是,我使用libconfig ++来解析我的配置文件.好吧,libconfig不支持多线程,因此我使用两个包装类来完成"支持".点是,其中一个失败:
class app_config {
friend class app_config_lock;
public:
app_config(char *file) :
cfg(new libconfig::Config()),
mutex(new boost::mutex())
{
cfg->readFile(file);
}
private:
boost::shared_ptr<libconfig::Config> cfg;
boost::shared_ptr<boost::mutex> mutex;
};
Run Code Online (Sandbox Code Playgroud)
从我的main.cpp文件调用时失败可怕:
app_main::app_main(int c, char **v) : argc(c), argv(v) {
// here need code to parse arguments and pass configuration file!.
try {
config = app_config("mscs.cfg");
} catch (libconfig::ParseException &e) {
cout << "Parse error at line " << e.getLine() << ": " << e.getError() << endl;
throw;
} catch (libconfig::FileIOException &e) {
cout << "Configuration …
Run Code Online (Sandbox Code Playgroud) c++ construction exception-handling member-variables function-try-block
我不知道我是否遗漏了某些内容,或者它确实不存在.在C++ 11标准中,添加了原始字符串文字:
string s = "\\w\\\\\\w"; // I hope I got that right
string s = R"(\w\\\w)"; // I'm pretty sure I got that right
Run Code Online (Sandbox Code Playgroud)
但我尝试使用原始字符文字的所有尝试都失败了:
constexpr char bslash = R('\'); // error: missing terminating ' character
constexpr char bslash = R'(\)'; // error: 'R' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
第二次尝试被认为是一个多字符常量!我发现使用类似于Raw字符文字的唯一方法是:
constexpr char slash = *R"(\)"; // All Ok.
Run Code Online (Sandbox Code Playgroud)
但我不喜欢这种表示法(取消引用字符串文字以存储第一个元素的副本),因为它有点令人困惑.
嗯,问题是什么?
我正在使用下面的代码通过Artifactory的REST API上传文件。我的问题是,当我通过GUI查看文件时,收到以下消息:
客户端未发布校验和值。如果您信任上载的工件,则可以通过单击“修复校验和”按钮来接受实际的校验和。
如何修复上传内容,以便此消息消失?
如果我通过GUI上传文件,则不提供校验和值,那么为什么在使用API时必须这样做?使用API修复校验和时,我可以调用额外的功能吗?
我还看到了此设置:https: //www.jfrog.com/confluence/display/RTF20/Handling+Checksums这与我的问题有关系吗?
string inFilePath = @"C:\temp\file.ext";
string inUrl = @"domain.com/repoKey/";
string username = "username";
string apiKey = "apikey";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(username+":"+apiKey)));
using (var stream = File.OpenRead(inFilePath))
{
var response = client.PutAsync(inUrl + stream.Name, new StreamContent(stream));
using (HttpContent content = response.Result.Content)
{
string data = content.ReadAsStringAsync().Result;
}
}
}
Run Code Online (Sandbox Code Playgroud)
更新
共有三种校验和和两组校验和组。
"checksums" : {
"sha1" : "94332c090bdcdd87bd86426c224bcc7dc1c5f784",
"md5" : "dcada413214a5bd7164c6961863f5111",
"sha256" : "049c671f48e94c1ad25500f64e4879312cae70f489edc21313334b3f77b631e6"
},
"originalChecksums" : …
Run Code Online (Sandbox Code Playgroud) 我的应用程序的每个用户都将选择他们的国家/地区,之后它将存储在cookie中并存储以供以后的请求使用.一切都运转正常,但我需要在会议开始时设置文化.我目前正在尝试将web.config中的文化设置为en-GB,然后使用Global.asax覆盖会话到en-US的文化.代码如下
protected void Session_Start(object sender, EventArgs e)
{
if (Globals.CountryID == 8)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
}
}
Run Code Online (Sandbox Code Playgroud)
countryID为8,文化在以下代码中设置为en-US.但是,当我导航到设置了ToString("C")的页面时,它仍然以GBP显示,文化仍然是en-GB.
有什么建议?
使用线程时,'invoke'用于避免'交叉线程'(1)
但是,有时'计时器对象'被用来避免'CrossThread'(2)
像这样(例如)
public partial class Form1 : Form
{
private bool bCheckState = false;
public Form1()
{
InitializeComponent();
}
//Button Click
private void btnWork_Click(object sender, EventArgs e)
{
Thread m_Thread = new Thread(new ThreadStart(Work));
m_Thread.Start();
}
private void Work()
{
bCheckState = true;
// not use invoke
}
private void timer_Tick(object sender, EventArgs e)
{
if (bCheckState)
{
//tbxDisplay is winform's textBox control - printing data
tbxDisplay.Text = bCheckState.ToString();
bCheckState = false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
哪一个更有效?'(1)和(2)之间'
如果我们在"计时器事件"中检查后在"线程"中分散处理的数据,而不使用"调用"或其他方法,是否会出现问题?(我们听说在打印'thread'中处理的数据时要避免'Cross-Thread',在'timer event'中散布带有附加'timer object'的数据经常被使用,因为它既不有益也无害.
c# ×3
.net ×2
asp.net-mvc ×2
c++ ×2
artifactory ×1
asp.net ×1
c++11 ×1
caching ×1
character ×1
construction ×1
css ×1
cultureinfo ×1
execution ×1
html ×1
jquery ×1
lambda ×1
linq-to-sql ×1
listbox ×1
routines ×1
uiculture ×1
winforms ×1