multithreading

How to tell iPhone OS function to stop/cancel?

I have an action which begins when the user taps a button on the screen (e.g. "Import"). At the same time, a UIToolbar appears on the bottom of the screen which gives the user the option to cancel this action. How can I properly send a cancel message to the initial function? If the user hits "Cancel," I do not want the "Import" to contin...

What thread handles modal dialog windows in .Net?

I have a pretty basic understanding of the GUI thread and the message loop, but I'm curious as to how that applies to one window starting a modal window. If I had to guess, I'd say that both windows are being run under the same GUI thread and that some parameter indicates that only events with the child window (the modal one) be executed...

ASP.NET Threading - can I do Async methods or do I use threading?

My environment - C# 3.5 and ASP.NET 4.0 and VS 2010 Apologies - am a bit new to some of the concepts related to threading and Async methods. My scenario is this: My site will periodically make a couple of GET/POSTS to an external site and collect some data This data will be cached in a central cache The periodic action will happen on...

Spring and synchronization for part of the method

I have a manager as Spring wired bean. I believe every bean defined for spring by default is wired as singleton. I have some methods in this bean which I need to synchronize. How should I be doing that then -- void zzz() { synchronized (this) { ... } } or void zzz() { synchronized (MyClass.class) { ... } } ? ...

Adding locks to the class by composition

I'm writing thread-safe class in C++. All of its public methods use locks (non-recursive spin locks). Private methods are lock-free. So, everything should be OK: user calls public method, it locks object and then does the work through private methods. But I got dead lock when a public method calls another public method. I've read that re...

timers in threading in .net

I want a timer tick/elapsed event inside a new thread. It seems like I cannot use the Windows timer. But if I use the Timers.Timer, it creates worked thread from the threadpool for each elapsed event. Is there a way to make these events to occur in the same thread? Update: Thank you everybody for answering this question. My intention...

C# - How to make this thread wait?

I have this: public class ServiceLibrary { public object result = null; private bool finished = false; public void testar() { ServiceReference.Service1SoapClient serviceReference = new ServiceReference.Service1SoapClient(); serviceReference.updateUserCompleted += new EventHandler<ServiceReference.updateUse...

Faking synchronous calls in Silverlight WP7

I'm porting some code from the full .NET framework to the WP7 version and I'm running into an issue with synchronous vs async calls. string response; string requestString = GenerateReqString(); HttpWebRequest req = (HttpWebRequest) WebRequest.Create("endpoint"); req.Method = "POST"; req.ContentType = "text/xml"; req.ContentLength...

C# How do I pass object back to main thread from worker thread?

How do I handle data returned from a worker thread public method? Thanks. ...

Replace critical section with SRW lock

If the application is targeted on Windows Vista or later, could we replace all critical sections with SRW locks? Since critical section is mutually exclusive, for usage it is equivalent to SRW locks in exclusive mode, right? According to MSDN, SRW is optimized both for speed and space. Is there any drawback for doing this? I'm not sure h...

socket client for android - best methods

I have a few questions about creating a socket client for android devices. 1) what is the best object/method to use to handle the socket.getInputStream() method. I've seen a few different ideas and before I start playing around with them, I'd like to hear it here first as to what you all think the best approach to handling the InputStr...

Performing one time initialization in multithreaded C# programs

Is the snippet below "safe" for performing some initialization once in a multithreaded program? I'm a bit worried that boxing/unboxing might cause some problem... private static object initialized = false; public static void Initialize() { lock (initialized) { if ((bool)initialized == false) { DoInitialization(); ...

TimerTask keeps running

I have a question about the behaviour of Timer class in Java. This is the code: http://pastebin.com/mqcL9b1n public class Main { public static void main(String[] args) { Main m = new Main(); m.foo(); m = null; } public void foo() { Timer t = new Timer(); t.schedule(new SysPrint()...

GREF increasing / decreasing in multi-threaded service (aidl) - what does it mean?

I have an android activity and a service implemented using aidl. Works like a champ, I have a callback setup to pass some thread notifications back to the UI, and that appears to work fine, with the exception of lots of GREF has increased to 101, 201,301,401, 501.. etc, and GREF has decreased. I did some searching online and found that ...

Connection pool problem with Spring and programmatic transaction management

Hi everyone ! I need your help in order to solve connection pool problem with Spring. I’m using Spring with Java 1.4 (no annotation). Here is the datasource and the connection pool definition: <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <...

C# Image: Attempted to read or write protected memory.

Hello, I'm writing C# application which saves picture box screen to JPEG files. One thread creating image: IntPtr copyPtr = new IntPtr((void*)pArray); image = new Bitmap(bitmapInfo.biWidth, Math.Abs(bitmapInfo.biHeight), bitmapInfo.biWidth * 3, PixelFormat.Format24bppRgb, copyPtr); lock (image) { this.CreateGraphics().DrawImage(im...

Looking at what happens when a c#/ASP.NET thread is terminated and how to get around problems

I'm working on a ASP.NET website that on some requests will run a very lengthy caching process. I'm wondering what happens exactly if the execution timeout is reached while it is still running in terms of how the code handles it. Particularly I am wondering about things like if the code is in the try of a try/finally block will the fina...

Android AsyncTask remains in running state after completing.

Hi, While working on an an application i noticed that the thread count keeps growing all the time AsyncTask Threads remain open for some reason (im sure they finished proccesing and exited) i have no idea why i keep creating more threads of this type and they keep running indefinitely. is there any way to verify that these threads are te...

How to implement AsyncCallback when importing rows?

Hello, I never used AsyncCallback. Need your help. When In Windows Form app I importing rows application form freezes. To prevent it, i think I can use AsyncCallback. foreach (DataRow dr in srcdt.Rows) { desdt.ImportRow(dr); } and while importing rows, to show in lebel.Text imported row count. Some help please. ...

Recycle-safe thread ID's and when thread stack gets freed?

Does the stack reserved/commited for a thread get freed when the thread terminates the thread object is destroyed (i.e. the thread is terminated and all handles to the thread are closed) ? More broadly, are there significant resources associated with a thread that has terminated, but still exists since there are valid handles to it...