to make multithread as singlethread


  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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
KelmenAuthor Commented:
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:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KelmenAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.