We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


to make multithread as singlethread

Kelmen asked
Medium Priority
Last Modified: 2012-06-21

  Me dunno really how to workout the subject. Basically I already have a threading stuff.
  What it do is in Windows Form, when I click a button, a process start (which call a web service, so can imagine the waiting needed). I use threading here as the process take long, so not freeze the form and cursor. When the process done, it will invoke my callback delegate to display the results. Working as expected, no problem.

private void StartJob()
  ThreadedProcess objTP = new ThreadedProcess();
  objTP.StartTranslator(parameter...., new Callback_Doing(Doing), new Callback_Done(Done));
  objTP = null;

public void Doing(...) {...}

public void Done(...) {...}

But now I in another routine, which is generating the results onto a file, so:
  result grabbed from Done().... *** AAA
  Write result into File...
  } until all-done;

How do I worked out the -AAA- part?
I reuse the StartJob(), which spin off a thread, but I have to wait for the result grabbed in Done().
Should I lookinto ThreadPool, AutoResetEvent ?
I can't find more details/samples from the MSDN, any good ref would be good for me too.

Watch Question

If you want to write all results to file in when thread exits, do this in the Done function. If you want to write every record or some other portion of data, do this in Doing function. Worker thread can pass results through parameters, or write them to some object like ArrayList, recordset etc.


I have no problem getting results back. Workaround is already done, but not using any threading approach.

I wanna see whether I can get the job done using threading way.
use the keyword: 'lock' to hold an object as token.. see this:

object token = new object();
ArrayList result ;

// and in your calling order, call the Doing first , then WriteResult..

// first line in Doing:
// here goes the Webservice calling
// save result in 'result'

// fist line in WriteResult
// here goes the writing issues

lock will forbid any otherthread from entering between { } until the thread that has the lock leave the {} ..all threads will wait.

use: Mutex obejct

see thius tutorial:

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


your input indeed work right for my topic title, but alas it doesn't really in my app context, but do give an idea.
Not your fault, by my, as I simplify my question to misleading, obviously.

At the end, I need to redesign the app.

Nevertheless, thx.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.