走过海棠暮

文章 评论 浏览 25

走过海棠暮 2024-10-09 14:38:15

据我所知,.NET 内存模型并不能保证一个线程中对变量所做的更改在另一个线程中可见。你需要一个内存屏障。最简单(尽管不是最有效)的组织方法是使用 lockInterlocked 方法。

顺便说一句,忙碌的等待并不是实现目标的最佳方法。也许您想切换到具有适当条件变量(Monitor(用 C# 的说法)用法?

As far as I know, the .NET memory model doesn't guarantee that the changes of a variable made in one thread will be visible in another thread. You need a memory barrier there. The simplest (though not the most efficient) way to organize that is by using lock or Interlocked methods.

By the way, busy waiting is not the best method to achieve your goal. Maybe you'd like to switch to the producer-consumer model with appropriate condition variable (Monitors in C# parlance) usage?

使用 bool 来同步多个线程是否安全?

走过海棠暮 2024-10-09 08:42:51

我认为你使用的语言并不禁止你开发一些免费的库等等。该技术的系统并非(全部)免费,但这并不意味着您不能用它来做开源产品。

如果你开发 C#,你就在某种程度上“赞助”了微软,微软并不真正喜欢开放软件,你可能会发现这是一个问题。

我是一名 C# 开发人员,对此没有任何问题,因为我在工作中编写的每个代码都是专有代码,所以不知何故我也是一名专有代码开发人员,我无法逃避这一点。

我没有看到专有代码有任何问题:)

I think the language you use does not forbid you to developing some free library or so on. The systems are not (all) free for this technology, but it doesn't mean that you can't do open source products with it.

If you develop C#, you are somehow "sponsoring" Microsoft, which doesn't really like open software, which you may find a problem.

I am a C# developer and have no problems with that, because every code I wrote in my work was a proprietary code, so somehow I am also a proprietary-code-developer, I can't run away from that.

And I don't see any problem on proprietary code :)

学习.NET;赞助我不同意的心态?

走过海棠暮 2024-10-09 07:47:37

它有一个 if 检查,但不知道如何处理结果。我想你希望它得到回显,所以它应该是这样的:

function postORempty($field)
{ 
echo ((isset($_POST[$field])) ? $_POST[$field] : ""); 
}

或者返回它:

function postORempty($field)
{ 
return ((isset($_POST[$field])) ? $_POST[$field] : ""); 
}

It has a if check but doesnt know what to do with the result. I presume you want it to be echoed so this is what it should be:

function postORempty($field)
{ 
echo ((isset($_POST[$field])) ? $_POST[$field] : ""); 
}

or return it:

function postORempty($field)
{ 
return ((isset($_POST[$field])) ? $_POST[$field] : ""); 
}

我的功能出了什么问题? (用户定义函数的新增内容)

走过海棠暮 2024-10-09 01:59:46

取出通配符匹配表达式(。*)

RewriteCond %{THE_REQUEST} ^index\.php
RewriteRule ^index\.php$ http://www.thisdomain.co.uk/$1 [R=301,L]

应该做您要寻找的事情。这样,您甚至可能不需要rewriteCond

Take out the wildcard match expression (.*):

RewriteCond %{THE_REQUEST} ^index\.php
RewriteRule ^index\.php$ http://www.thisdomain.co.uk/$1 [R=301,L]

Should do what you are looking for. With this, you may not even need the RewriteCond

index.php 重定向的正则表达式(但有点复杂!)

走过海棠暮 2024-10-08 20:49:32

read_ahead 与delayed_write 相反,因为读取与写入相反。

如果您想读取并发送更大的内存块,则不需要 read_ahead,只需读取大块并发送它们(此处保存的操作系统调用不多)。

来自 read_ahead 上的 file:open/2 联机帮助页:

如果 read/2 调用的大小不显着小于或什至大于 Size
字节,预计不会有任何性能提升。

打开时不需要指定和索引。只需使用 pwrite/3position/2write/2

但是在文件的不同位置写入可能只会减少 delayed_write 的增益,因为(也是 文件:open/2):

缓冲的
数据也会在其他文件之前刷新
执行 write/2 以外的操作。

如果您有多个位置的大量数据,请将它们收集在 {Location, Bytes} 列表中,并时不时用 file:pwrite/2 一口气完成。这可以映射到非常高效的 writev(2) 系统调用,一次性写入多个块。

read_ahead is kind of the opposite of delayed_write in the sense that reading is the opposite of writing.

If you want to read and send bigger chunks of memory you don't need read_ahead, just read big chunks and send them (not many os calls to save here).

From the file:open/2 manpage on read_ahead:

If read/2 calls are for sizes not significantly less than, or even greater than Size
bytes, no performance gain can be expected.

You don't need to specify and index when opening. Just use pwrite/3 or a combination of position/2 and write/2.

But writing in different positions of the file might just reduce the gain of delayed_write since (also manpage of file:open/2):

The buffered
data is also flushed before some other file
operation than write/2 is executed.

If you have chunks of data for several positions collect them in a list of {Location, Bytes} and from time to time write them with file:pwrite/2 all in one go. This can map to very efficient writev(2) system call that writes several chunks in one go.

将 open(Filename, {delayed_write, Size, Delay}) 与索引结合起来

走过海棠暮 2024-10-08 18:43:43

你的问题实际上与闭包无关。当您这样做时:

modMe = secretVar;

您只是创建一个指向相同数组的新变量。您对一个变量所做的操作将反映在两个变量中,因为它们指向同一事物。

如果您想对数组执行某种修改(同时保留原始数组),您需要先复制它:

var copied = [];
for(var i = 0; i < secretVar.length; i++){
    copied.push(secretVar[i]);
}

编辑:顺便说一句,当您说您使用闭包来“保护变量”时,您并没有保护它们防止被执行闭包的返回函数修改。您刚刚做到了这一点,以便从这些函数的范围之外无法访问该变量。但是,在作用域内,例如当您执行切片时,该变量就在那里并且可供该函数访问,并且不会仅仅因为它是一个闭包而受到“保护”。

编辑 2:如果您要经常复制数组,您可以通过创建一个封闭函数来为您进行复制来消除迭代的一些麻烦:

closure = function() {
    var secretVar = 'Secret';
    var clone = function(){
        var clonedArr = [];
        var length = secretVar.length;
        for(var i = 0; i < length; i++){
            clonedArr.push(secretVar[i]);
        }
        return clonedArr;
    }

    return {
        "msg" : function() {
            var duplicate = clone();
        }
    };
}();

Your problem actually has nothing to do with closures. When you do:

modMe = secretVar;

You are just creating a new variable pointing to the same array. What you do to one will be reflected in both variables, since they are pointing to the same thing.

If you want to perform some sort of modification on the array (while maintaining the original), you need to copy it first:

var copied = [];
for(var i = 0; i < secretVar.length; i++){
    copied.push(secretVar[i]);
}

Edit: As an aside, when you say you are using closures to "protect variables" you're not protecting them from being modified by the returned functions that performed the closure. You just made it so that the variable is inaccessible from outside the scope of those functions. But, inside the scope, such as when you do your slice, the variable is there and accessible to that function and is not "protected" just because it is a closure.

Edit 2: If you are going to be copying the array frequently, you can eliminate some of the irritation of the iteration by creating a closured function to do the copying for you:

closure = function() {
    var secretVar = 'Secret';
    var clone = function(){
        var clonedArr = [];
        var length = secretVar.length;
        for(var i = 0; i < length; i++){
            clonedArr.push(secretVar[i]);
        }
        return clonedArr;
    }

    return {
        "msg" : function() {
            var duplicate = clone();
        }
    };
}();

Javascript 闭包,维护外部对象

走过海棠暮 2024-10-08 18:43:06

您必须调用 setIs24HourView 函数并为此发送 true。
当时间选择器处于 24 模式时 AM/PM 将消失。

TimePicker tpHourMin = (TimePicker) findViewById(R.id.timePicker);
tpHourMin.setIs24HourView(true);

You must call setIs24HourView function and send true for that.
when time picker are in 24 mode AM/PM will be disappear.

TimePicker tpHourMin = (TimePicker) findViewById(R.id.timePicker);
tpHourMin.setIs24HourView(true);

是否可以从 TimePicker 中删除 AM/PM 按钮?

走过海棠暮 2024-10-08 14:37:57

通过将 Materialize 与自定义样式表结合使用,您可以实现如下效果:

CSS 代码

.custom_checkbox[type="checkbox"]:checked + span:not(.lever)::before {
  border: 2px solid transparent;
  border-bottom: 2px solid #ffd600;
  border-right: 2px solid #ffd600;
  background: transparent;
}

< strong>HTML 代码

<label>
    <input type="checkbox" class="custom_checkbox" />
    <span>Text</span>
</label>

演示

JSFiddle 演示

By using Materialize with a custom stylesheet, you can achieve something like this:

CSS code

.custom_checkbox[type="checkbox"]:checked + span:not(.lever)::before {
  border: 2px solid transparent;
  border-bottom: 2px solid #ffd600;
  border-right: 2px solid #ffd600;
  background: transparent;
}

HTML code

<label>
    <input type="checkbox" class="custom_checkbox" />
    <span>Text</span>
</label>

Demo

JSFiddle demo

如何使用 CSS 设置复选框样式

走过海棠暮 2024-10-08 13:34:48

对于基于 Web 的,您可以尝试用于 Java 的 GWT (Google Web Tookit)。 Flex-AIR将是桌面应用程序的另一个候选者。

For web based, you can try GWT (Google Web Tookit) for java. Flex-AIR will be the another candidate for desktop application.

如何为我自己的应用程序构建一个漂亮的类似 Android 的用户界面

走过海棠暮 2024-10-08 12:37:12

还有另一种方法可以使用 System.Xml 功能来转义此类字符。

您只需将 XmlWriterSettings 的 CheckCharacters 标志设置为 false。

using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { CheckCharacters = false }))
{
  document.Save(xmlWriter);
}

但如果您想读取 xml,则必须将 XmlReaderSettings 的相同标志设置为 false。 :)

using (XmlReader reader = XmlReader.Create(stringReader, new XmlReaderSettings { CheckCharacters = false }))
{
  document = XDocument.Load(reader);
}

There is another way to escape such characters by using System.Xml features.

You just need to set CheckCharacters flag to false for XmlWriterSettings.

using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { CheckCharacters = false }))
{
  document.Save(xmlWriter);
}

But you have to set the same flag to false for XmlReaderSettings if you want to read the xml. :)

using (XmlReader reader = XmlReader.Create(stringReader, new XmlReaderSettings { CheckCharacters = false }))
{
  document = XDocument.Load(reader);
}

在 XML 文件中保存转义字符 0x1b

走过海棠暮 2024-10-08 11:29:17

您应该了解的情况,

CreateFileW(L"D:\\1\\test.txt", GENERIC_READ, 0, 0, CREATE_NEW, 0, 0);
// A file has been created.

CreateFileW(L"D:\\1\\test.txt", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
// Of course, the file will be opened well.

CreateFileW(L"D:\\1\\\\test.txt", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
// It works well too. Windows subsystem does canonicalize that.

CreateFileW(L"\\\\?\\D:\\1\\\\test.txt", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
// '\\?\' prefix tell Windows "Don't touch my path, just send it to filesystem"
// So it will be failed.

http://msdn。 microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath
我不知道 .NET 如何包装这个 api。我想汉斯·帕桑特可能对此很了解。 :)

The case you should know,

CreateFileW(L"D:\\1\\test.txt", GENERIC_READ, 0, 0, CREATE_NEW, 0, 0);
// A file has been created.

CreateFileW(L"D:\\1\\test.txt", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
// Of course, the file will be opened well.

CreateFileW(L"D:\\1\\\\test.txt", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
// It works well too. Windows subsystem does canonicalize that.

CreateFileW(L"\\\\?\\D:\\1\\\\test.txt", GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
// '\\?\' prefix tell Windows "Don't touch my path, just send it to filesystem"
// So it will be failed.

http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath
I have no idea how .NET wraps this api. I guess Hans Passant might knows well about this. :)

File.Copy() 或 Directory.CreateDirectory() 方法的路径变量中的额外斜杠

走过海棠暮 2024-10-08 03:07:27

坦率地说,我真的不知道有什么好的在线网站可以做到这一点。

Google 给了我这个网站,但我尝试了一下,它确实有点麻烦,而且很难合作。

我真的建议你会发现在你的机器上安装一些数据库(如 MySQL / SQL Server Express)并尝试一下会容易得多。

安装 SQL Server Express 等软件非常简单。您只需从此处下载 db + 工具,快速安装即可完成所有设置要获取

示例数据,您可以随时下载 Adventureworks 数据库
列出了有关如何使用 SQL Express 运行 AdventureWorks 数据库的分步详细信息 此处

Frankly, I do not really know of any GOOD online site for doing this.

Google gave me this site but i tried it out and its really a bit cumbersome and difficult to work with.

I would really suggest that you will find it a LOT easier to install some database like MySQL / SQL Server Express on your machine and try things out.

Installing something like SQL Server Express is really easy. You can just download the db + tools from here, a quick install and you will be all set to go

For the sample data, you can always download the Adventureworks database.
Step by step details on how to get the AdventureWorks database running with SQL Express are listed here

假的 mysql 服务器来运行 sql 命令以进行练习

走过海棠暮 2024-10-08 00:52:37

像这样使用 .className

$('.class2 , .class3, .class3').bind('click', function() { 
  alert(this.className);
  location.href = "test.htm"; 
});

您可以 不过,可以是这些类中的 1 到 3 个,包括其他不相关的类。

或者,因为如果您想使用 .hasClass() 测试它,您实际上只有 2 个 这也是一个选项:

$('.class2 , .class3').bind('click', function() { 
  var c = $(this).hasClass("class2") ? "class2" : "class3";
  alert(c);
  location.href = "test.htm"; 
});

You can use .className like this:

$('.class2 , .class3, .class3').bind('click', function() { 
  alert(this.className);
  location.href = "test.htm"; 
});

It can be anywhere from 1 to 3 of those classes though, including other unrelated classes.

Or, since you only actually have 2 if you want to test it using .hasClass() that's an option as well:

$('.class2 , .class3').bind('click', function() { 
  var c = $(this).hasClass("class2") ? "class2" : "class3";
  alert(c);
  location.href = "test.htm"; 
});

多个班级事件在一起,如何获取当前班级名称

走过海棠暮 2024-10-07 21:39:33

正确的答案是来自“max”的答案(手动设置你的 HOME 环境变量),但它可能有助于一些人理解问题发生的原因(随着 Git 在世界各地获得更多用户,这将变得非常常见)。

Cygwin 将 $HOME 设置为 /home/yourname,但该变量在 Windows 环境中未知。因此,如果您打开 bash 窗口并执行 env | grep HOME 你会看到这里提到的所有三个“HOME”变量,你可能想知道为什么 Gitextensions 不使用正确的 cygwin HOME - 这是因为它的 .bat 文件调用看不到它 - 它只看到你看到的内容在 Windows 控制台中进行“设置”。

令人费解的是,为什么它不稍后进行此评估并获取正确的 cygwin 路径,因为它知道如何调用 bash,但是(至少在 2.41 之前的版本中)您必须在设置或 .gitconfig 中进行手动更改。

The correct answer is the one from 'max' (set your HOME env var manually), but it may help some to understand why the problem is happening (as Git gets more users around the world it's going to be very common).

Cygwin sets $HOME to /home/yourname, but that variable is not known in the Windows environment. So if you open a bash window and do env | grep HOME you'll see all three 'HOME' variables mentioned here, and you might wonder why Gitextensions doesn't use your proper cygwin HOME - which is because its .bat file invocation doesn't see it - it only sees what you see from doing 'set' in a windows console.

It's mystifying why it doesn't do this evaluation later and get the proper cygwin path since it knows how to invoke bash, but (at least in versions up to 2.41) you have to do this manual change in the settings or in .gitconfig.

无法获取 git 扩展来将某些内容推送到 github SSH 问题

更多

推荐作者

kaipeng

文章 0 评论 0

吐个泡泡

文章 0 评论 0

沧桑㈠

文章 0 评论 0

御宅男

文章 0 评论 0

泪眸﹌

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文