thread-safety

How to use Thread to release the application from freezing in c#

淺唱寂寞╮ 提交于 2020-01-24 22:12:12
问题 I have the code below for scanning but When i press the button to start scanning, the windows form freezes and i can not move the form or minimizie/colse it until the process will be finished! i'm new in working with Thread but i tried to add Thread andi couldn't solve the problem. Does anyone know to where (how) can i write a Thread to release my form from freezing? Thanks. public Bitmap GetBitmapFromRawData(int w, int h, byte[] data) { //Do sth } //button to start the scan proccess private

How to use Thread to release the application from freezing in c#

社会主义新天地 提交于 2020-01-24 22:11:48
问题 I have the code below for scanning but When i press the button to start scanning, the windows form freezes and i can not move the form or minimizie/colse it until the process will be finished! i'm new in working with Thread but i tried to add Thread andi couldn't solve the problem. Does anyone know to where (how) can i write a Thread to release my form from freezing? Thanks. public Bitmap GetBitmapFromRawData(int w, int h, byte[] data) { //Do sth } //button to start the scan proccess private

Updating ObservableCollection from non UI thread

时光总嘲笑我的痴心妄想 提交于 2020-01-24 15:42:06
问题 I am working on a Windows 8 Store app. I have a timer that calls a delegate every two minutes and makes an async web request. The resulting data is added to an observablecollection that is bound to a UI element. Doing this throws an exception because the UI is being modified on a non UI thread. In other places in my code I have done this await Window.Current.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, async () => { ui code here } But this is causing a crash with Window

Is there a way to figure out what thread an NSManagedObjectContext is on?

只谈情不闲聊 提交于 2020-01-24 10:35:07
问题 My understanding of threads with respect to an NSManagedObjectContext is that it can only execute core data fetch requests, deletes, etc., on the thread from which it was created. Is there any way to check to see what thread an NSManagedObjectContext was created on, or if at a particular point of execution the current thread is that of a particular NSManagedObjectContext ? Thanks! 回答1: My understanding of threads with respect to an NSManagedObjectContext is that it can only execute core data

Is there any optimization for thread safety in for loop of Java?

只谈情不闲聊 提交于 2020-01-23 04:28:27
问题 I have a snippet of code that change a counter in two threads. It's not thread safe because I didn't put any atomic variable or lock in the code. It gives the right result as I expected if the code only run once, but I want to run it for several times, so I put the code into a for loop. And the question is that only the first or the first two loops will generate the result I expect. For the rest of the loops, the results are always 0, which seems to be thread safe. Is there any inner operator

Should I synchronize a static volatile variable?

无人久伴 提交于 2020-01-22 19:40:13
问题 There are a few questions on this subject, but most skirt around this issue because it's not the intent of the question. If I have a static volatile in my class: private static volatile MyObj obj = null; and in a method below I do: public MyObj getMyObj() { if (obj == null) { obj = new MyObj();// costly initialisation } return obj; } will I need to synchronize to ensure only one thread writes to the field, or will any writes be immediately visible to other threads evaluating the obj == null

zmq: can multiple threads PUSH in a simple PUSH-PULL pattern

泄露秘密 提交于 2020-01-22 14:56:09
问题 I have two processes: a producer which pushes messages via ZMQ to a consumer in a simple PULL-PUSH point-to-point pattern. The producer has several internal threads that send() via zmq. However, 0MQ's docs suggest not to share sockets between threads . Must I use a single thread to send? Assuming there is no strict requirement for keeping the sending order between the threads, doesn't the fact that the socket is a one-directional simplex allow multiple threads to use it without introducing

zmq: can multiple threads PUSH in a simple PUSH-PULL pattern

感情迁移 提交于 2020-01-22 14:56:04
问题 I have two processes: a producer which pushes messages via ZMQ to a consumer in a simple PULL-PUSH point-to-point pattern. The producer has several internal threads that send() via zmq. However, 0MQ's docs suggest not to share sockets between threads . Must I use a single thread to send? Assuming there is no strict requirement for keeping the sending order between the threads, doesn't the fact that the socket is a one-directional simplex allow multiple threads to use it without introducing

Reproducing Unexpected Behavior w/Cross-Modifying Code on x86-64 CPUs

╄→尐↘猪︶ㄣ 提交于 2020-01-22 13:43:26
问题 Question What are some ideas for cross-modifying code that could trigger unexpected behavior on x86 or x86-x64 systems, where everything is done correctly in the cross-modifying code, with the exception of executing a serializing instruction on the executing processor prior to executing the modified code? As noted below, I have a Core 2 Duo E6600 processor to test on, which is explicitly mentioned as a processor that is prone to issues regarding this. I will test any ideas shared with me on

Is CreateDirectory() in C# thread-safe?

妖精的绣舞 提交于 2020-01-22 11:17:44
问题 Can I safely attempt to create the same directory from two different threads, without having one of them throw an exception, or run into other issues? Note that according to MSDN, it is OK to call CreateDirectory() on a directory which already exists, in which case the method is expected to do nothing. 回答1: The Directory.CreateDirectory call itself is safe to make from multiple threads. It will not corrupt program or file system state if you do so. However it's not possible to call Directory