Learn how to a build a cloud-first strategyRegister Now


to make multithread as singlethread

Posted on 2006-03-23
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.

Question by:Kelmen
  • 2
LVL 48

Expert Comment

ID: 16267610
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.

Author Comment

ID: 16276865
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.

Accepted Solution

nehaya earned 1500 total points
ID: 16494478
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:

Author Comment

ID: 16495086
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.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question