multithreading

Thread behavior on multicore machines

Does the threads of a single process run in parallel on a multi-core machine on windows XP? Is the behavior same on different windows versions (windows server editions) I have heard that only threads of different processes run in parallel. ...

How to avoid a thread freezing when Main Application is Busy

Hi, I'm having a bit of a problem. I want to display a progress form that just shows an animation on a when the main application preforms heavy operations. I've done this in a thread and it works fine when the user isn't preforming any operations. But it just stops when my main application is busy. I'm not able to put Application.Pro...

Silverlight, Updating the UI during processing

Hi, I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ui to update: private void DoUpload() { foreach (UploadFile file in fileInfos) { int BUFFERSIZE = 1024;...

How to have a certain thread deal with an event (not to do with UI threading issues)?

I am in the process of teaching myself thread based programming techniques and this question may be way off base... I'm not even sure if this is possible or indeed even the right approach to this problem. Please feel to correct me in what question I should be asking if appropriate. I am trying to have a certain thread deal with an even...

Are javax.persistence.Query objects cachable?

I'm writing a stateless EJB. I had methods like: public String getXxx(final String userId) throws ... { final Query query = em.createNativeQuery(...); query.setParameter(1, userId); return (String)query.getSingleResult(); } Can I cache the Query object instantiating it at load time and using it in a multi-thread environmen...

Memory barriers and large structs?

Let's say I've got a struct that consist of 100 bytes. What guarantees have I got about the following code? m_myLargeStruct = someValue; // copying 100 bytes Thread.MemoryBarrier(); // Executed by another thread, after "Thread.MemoryBarrier" was called by the first thread Console.WriteLine(m_myLargeStruct.ToString()); Does the memo...

Raise event from http listener (Async listener handler)

Hello, I have created an simple web server, leveraging .NET HttpListener class. I am using ThreadPool.QueueUserWorkItem() to spawn a thread to listen to incoming requests. Threaded method uses HttpListener.BeginGetContext(callback, listener), and in callback method I resume with HttpListener.EndGetContext() as well as raise an even to no...

How to stop BackgroundWorker on Form's Closing event?

I have a form that spawns a BackgroundWorker, that should update form's own textbox (on main thread), hence Invoke((Action) (...)); call. If in HandleClosingEvent I just do bgWorker.CancelAsync() then I get ObjectDisposedException on Invoke(...) call, understandably. But if I sit in HandleClosingEvent and wait for bgWorker to be done, th...

Using memory barriers

In the following code sample, does the memory barrier in FuncA is required to ensure that the most up-to-date value is read? class Foo { DateTime m_bar; void FuncA() // invoked by thread X { Thread.MemoryBarrier(); // is required? Console.WriteLine(m_bar); } void FuncB() // invoked by thread Y { m_...

Simulate the page lifecycle to grab the html from the UI layer

I'm working with a rather large .net web application. Users want to be able to export reports to PDF. Since the reports are based on aggregation of many layers of data, the best way to get an accurate snapshot is to actually take a snapshot of the UI. I can take the html of the UI and parse that to a PDF file. Since the UI may take up ...

In depth C# Book to read next

I have recently finished reading C# in depth by Jon Skeet and I'm looking for the next book to read, one that extends a little more "in depth" my knowledge of c# and .NET in general and I'd be open to other kind of books. I've read Code Complete and The Mythical Man-Month, and though I find them both to be awesome, I'm looking more for a...

UIActivityIndicatorView with UITableView in Navigation Controller

Hello guys, I am working on a an application which is very simple a navigation controller with a table view when the user clicks a row, he is directed to the details view. However, the details view pulls data from Core Data. i am pulling a relatively large amount of data that takes about three seconds to load. I wanted to add that UIA...

Cocoa WebView cross-thread access

I have a C++ class running in its own thread that needs to execute some javascript in a WebView that's part of a Cocoa app. I have the C++ app call a method in the Cocoa window's controller and it in turns runs the javascript, passing in the data. It seems to work part of the time, but crash a lot of the time as well (somewhere in WebVie...

Fetching Core Data in the background

Hello All, I have a Navigation View with a Table View, when a row is clicked, the row indexPath is passed to the next view. in the Details view viewDidLoad, i am fetching data from Core Data. i use the fetching from the application delegate [appDelegate loadItem:i]; As you can see i am passing one integer only which carries the row nu...

When do writes/reads affect main memory?

When I write a value into a field, what guarantees do I get regarding when the new value will be saved in the main memory? For example, how do I know that the processor don't keep the new value in it's private cache, but updated the main memory? Another example: int m_foo; void Read() // executed by thread X (on processor #0) { Co...

Silverlight, cross thread ui update problem

Hi, I have this class: public class UploadFile : INotifyPropertyChanged { private string name; public string Name { get { return name; } set { name = value; OnPropertyChanged("Name"); } } private FileInfo fileInfo; public FileI...

How to start/stop a monitoring Delphi thread on demand?

I've been looking for a way to monitor for specific registry changes in Delphi. Found a solution at about.com: procedure TRegMonitorThread.Execute; begin InitThread; // method omitted here while not Terminated do begin if WaitForSingleObject(FEvent, INFINITE) = WAIT_OBJECT_0 then begin fChangeData.RootKey := RootKey;...

(Delphi 2009) idIRC, MDI, and problems with hanging.

I'm working on an IRC client. I've hit a majors snag which, up until not I've been able to work around. I'll show code below. What's I'm having a problem with is creating MDI child windows within the event handlers of idIRC. For example, if I want to create a new channel form (FrmChannel), I can accomplish this easily by calling it's c...

How does memory fences affect "freshness" of data?

I have a question about the following code sample (taken from: http://www.albahari.com/threading/part4.aspx#_NonBlockingSynch) class Foo { int _answer; bool _complete; void A() { _answer = 123; Thread.MemoryBarrier(); // Barrier 1 _complete = true; Thread.MemoryBarrier(); // Barrier 2 } ...

how to let a worker thread update the ui in window forms [without using Control.Invoke()] ?

i know the way that uses the Control.InvokeRequired() and Control.Invoke(). but i was wondering if its possible to use some other method to alert the ui thread that the Data was changed and then let the ui thread update its controls without using control.invoke(). as far as i remember this was possible before in mfc by sending message...