单身和线程安全?(Singleton and Thread Safety?)
我目前正在开发一个“Singleton”类,但它必须承受线程安全,因为我不仅访问,而且设置一些东西..我想知道我怎么能这样 - 因为它似乎锁定的东西与当我不知道它在做什么以及我是否必须使每个方法线程都安全时,
lock(object)
感觉有点hacky?到目前为止,我有这个非线程安全的代码 - 因为在每个线程中应该访问相同的数据。 我怎样才能最好地使它保持线程安全并保持单身?
public class AppSession() { private static AppSession _instance = new AppSession(); public static AppSession Instance { get { return _instance; } } private AppSession() { } private string _actionName = "none"; private DateTime? _actionTime = null; public void ActionExecuted(string action) { _actionName = action ?? String.Empty; _actionTime = DateTime.UtcNow; } public LastAction { get { return $"{_action} at {_actionTime?.Value.ToString()}"; } } }
I'm currently developping a "Singleton" class, but it has to withstand thread safety as I'm not only accessing, but also settings some stuff.. I was wondering how I could to this - as it seems the locking of stuff with
lock(object)
feels somewhat hacky when I don't know what it's actually doing and if I have to make every single method thread safe as well?So far I have this non thread safe code - as in each thread should access the same data. How would I best go about making it thread safe and keep it a singleton?
public class AppSession() { private static AppSession _instance = new AppSession(); public static AppSession Instance { get { return _instance; } } private AppSession() { } private string _actionName = "none"; private DateTime? _actionTime = null; public void ActionExecuted(string action) { _actionName = action ?? String.Empty; _actionTime = DateTime.UtcNow; } public LastAction { get { return $"{_action} at {_actionTime?.Value.ToString()}"; } } }
原文:https://stackoverflow.com/questions/42470041
最满意答案
不幸的是,似乎
kashida
从CSS3文本中删除并延迟了CSS4文本 ,所以如果你想用Kashida证明你的文本,你应该尝试移植harfbuzz-old 添加kashida算法 (它的算法从新一代的harfbuzz, ref中删除),这是基于此处存档的Microsoft规范。 这是Microsoft的kashida插入优先级表,您应该尝试以某种方式实现:添加Kashida(«»)用于HTML本身的文本样式并不是一个好主意(因为如果用户复制文本它将包含添加的Kashidas,它将使浏览器在页面中找到问题)但是当前webkit bug / blink bug (Safari / Chrome)版本不支持在内联( 伪 )元素期间加入草书脚本字符(如阿拉伯语/波斯语),似乎没有任何机会在不插入Kashida的情况下获得此类理由(或者您应该通过以下方式处理oncopy事件你自己有自己的问题)。
有趣的是,微软正在扩展IE Kashida理由实施,以支持更有趣的事情,如text-kashida-space (配置kashida与白色空间扩展的比率,同时文本证明)。 似乎我们必须再等十年才能在所有主流浏览器中实现这些功能。
Unfortunately seems
kashida
is dropped from CSS3 text and deferred for CSS4 text, so if you want justify your text with Kashida, you should try porting harfbuzz-old adding kashida algorithm (that its algorithm is removed from newer generation of harfbuzz, ref) which is based on a Microsoft specification that is archived here. Here is Microsoft's kashida insertion priority table that you should try to implement somehow:ّAdding Kashida («ـ») for text styling on HTML itself is not a good idea (because if user copy the text it will contains added Kashidas and it will make problem for browsers find-in-page) however as current webkitbug/blinkbug (Safari/Chrome) versions do not support joining cursive script characters (like Arabic/Persian) during inline (pseudo)elements there seems there is not any chance you get this type of justification without inserting Kashida (or you should handle oncopy event by your own that has its own problems).
It is also interesting that Microsoft is extended IE Kashida justification implementation to support more interesting things like text-kashida-space (configure ratio of kashida to white space expansion while text justifying). Seems we must wait another decade to these get implemented across all major browsers.
相关问答
更多-
我不知道阿拉伯语脚本,但也许您可以尝试基于以下内容: 您可以使用简单的foreach循环遍历字符串中的所有字符。 然后,您可以检查该字符的“Unicode类别”(请参阅MSDN )。 如果我理解正确,您需要“NonSpacingMark”类别。 一些示例代码: string s = " وَجَلَّ فی "; foreach (char c in s) { Console.Write(c); Console.WriteLine(Char.GetUnicodeCategory(c)); } ...
-
经过一天的努力,我自己管理了,答案就在于此 [TBXML textForElement:element] // Method 代替 element->text. 希望它将有助于未来的其他用户。 I managed it myself after one day efforts, answer lies in [TBXML textForElement:element] // Method instead of element->text. Hope it will helps for other ...
-
我在这方面没有太多经验,但是当我尝试这个时,我没有阿拉伯字符的问题: require(tm) require(tm.plugin.webmining) require(SnowballC) corpus <- WebCorpus(GoogleNewsSource("سلام")) corpus inspect(corpus) tdm <- TermDocumentMatrix(corpus) 确保在操作系统和IDE上安装正确的字体。 ```{r} y <<- dget("file") # get th ...
-
我已经从我的朋友那里得到了解决上述问题的解决方案。 和这里分享一样.. 如果您有.ttf文件,那么首先在eclipse中打开您的项目并将.ttf文件复制到assets文件夹中,该文件夹将位于您的项目层次结构中。 然后打开想要使用该字体的.java文件,只需执行以下步骤: - First Typeface font1; TextView txt1; EditText edtxt; 第二:在onCreate方法只需写下这个代码。 /*here fonttype.ttf is the file which wa ...
-
尝试将postData设置为使用UTF 8而不是ASCII编码进行编码: postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; Try to set the postData to be encoded with UTF 8 instead of ASCII encoding: postData = [post dataUsingEncoding:NSUTF8StringEncoding all ...
-
问题是URL没有正确解析,因为有阿拉伯语文本,它正在解析为?????。png。 解决方案是在发送请求之前编码名称的阿拉伯语部分,然后我能够点击图像并获得成功的响应。 编码( encodeURI )正确地将URL解析为: HTTP://......./......./...../%D8%A8%D8%A7%D8%AC%D9%86%D8%AF%D9%88 %D8%AD.png 使用以下代码: var imgUrl:String = "http://....../..../...../"; var imgPart: ...
-
不幸的是,似乎kashida从CSS3文本中删除并延迟了CSS4文本 ,所以如果你想用Kashida证明你的文本,你应该尝试移植harfbuzz-old 添加kashida算法 (它的算法从新一代的harfbuzz, ref中删除),这是基于此处存档的Microsoft规范。 这是Microsoft的kashida插入优先级表,您应该尝试以某种方式实现: 添加Kashida(«»)用于HTML本身的文本样式并不是一个好主意(因为如果用户复制文本它将包含添加的Kashidas,它将使浏览器在页面中找到问题)但 ...
-
使用原始小提琴,只需添加display:inline-block; 到.download_button1 ,它将按预期工作。 在browserstack上查看结果 Using your original fiddle, just add display:inline-block; to .download_button1 and it will work as expected. see results on browserstack
-
TKinter的阿拉伯语文本(Arabic text in TKinter)[2024-03-08]
您只需将您的编码设置为UTF-8 ,方法是将此行设置为Python文件中的第一行(在您的代码之前): # -*- coding: UTF-8 -*- 这是一个代码示例: # -*- coding: UTF-8 -*- from Tkinter import * root = Tk() root.title('Alram') root.geometry("1500x600") mytext= 'ذكرت تقارير' #Arabic text msg = Message(root, bg="red", te ... -
使用android:textDirection和“ anyRtl ”。 从xml:将此行: android:textDirection="anyRtl"到TextView标记中。 来自代码: textview.setTextDirection(View.TEXT_DIRECTION_ANY_RTL); PS:自API 17+以来。 Use android:textDirection with "anyRtl". From xml: Add this line: android:textDirection=" ...