Friday, February 11, 2005

WaitForSingleObject(Handle, Timeout)

Recently I was working on a problem where I had to create new process on a click of a button. With this, I needed some callback or signal when this new process terminates. This new process was launched on a new thread. I looked into the Thread Class but there was no out of box functionality to achieve this. So I end up writing this code.

Here is the PInvoke Declaration

[DllImport("Kernel32.dll", CharSet=CharSet.Unicode,SetLastError=true)]
static extern uint WaitForSingleObject(
IntPtr HANDLE,
uint Timeout);

Creating a new Thread to start our process…

newThread = new Thread(new ThreadStart(StartNewApplication));
newThread.Name = "ClientApplication";
newThread.Start();

private void StartNewApplication()
{
//Declarations...
const uint INFINITE = 0xFFFFFFFF;
uint returnValue;
int error;

//Creating a new process
Process pr = new Process();
pr.StartInfo.FileName="RemotingServer.exe";
pr.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
pr.Start();


//Using WaitForSingleObject to wait till the threads give a
//signal. As we want to get signaled when the thread gets
//terminated, we set timeout time as "Infinite".
IntPtr HANDLE = pr.Handle;
returnValue = WaitForSingleObject(HANDLE,INFINITE);
if (returnValue == 0xFFFFFFFF)
{
//Getting error code...
error = Marshal.GetLastWin32Error();
}
else
{
//Code which we want to execute after the thread has been terminated
}
}

45 Comments:

Anonymous Anonymous said...

Check out the WaitForExit() method on the Process class. It will do exactly what you want without having to pinvoke (WaitForExit actually uses WaitForSingleObject internally).

5:44 AM  
Anonymous Anonymous said...

Hello, Just wandering the blogosphere and happened on your blog. I like the way how you have put it all together. I'll be coming back again.

Regards,

AIU Degree Online

12:37 AM  
Anonymous Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

11:00 AM  
Anonymous Anonymous said...

Do You interesting of [b]Female use of Viagra[/b]? You can find below...
[size=10]>>>[url=http://listita.info/go.php?sid=1][b]Female use of Viagra[/b][/url]<<<[/size]

[URL=http://imgwebsearch.com/30269/link/buy%20viagra/1_valentine3.html][IMG]http://imgwebsearch.com/30269/img0/buy%20viagra/1_valentine3.png[/IMG][/URL]
[URL=http://imgwebsearch.com/30269/link/buy%20viagra/3_headsex1.html][IMG]http://imgwebsearch.com/30269/img0/buy%20viagra/3_headsex1.png[/IMG][/URL]
[b]Bonus Policy[/b]
Order 3 or more products and get free Regular Airmail shipping!
Free Regular Airmail shipping for orders starting with $200.00!

Free insurance (guaranteed reshipment if delivery failed) for orders starting with $300.00!
[b]Description[/b]

Generic Viagra (sildenafil citrate; brand names include: Aphrodil / Edegra / Erasmo / Penegra / Revatio / Supra / Zwagra) is an effective treatment for erectile dysfunction regardless of the cause or duration of the problem or the age of the patient.
Sildenafil Citrate is the active ingredient used to treat erectile dysfunction (impotence) in men. It can help men who have erectile dysfunction get and sustain an erection when they are sexually excited.
Generic Viagra is manufactured in accordance with World Health Organization standards and guidelines (WHO-GMP). Also [url=http://twitter.com/jetlyca]q Buy Viagra Online[/url] you can find on our sites.
Generic [url=http://viagra.olistupa.ru]Viagra Super Active[/url] is made with thorough reverse engineering for the sildenafil citrate molecule - a totally different process of making sildenafil and its reaction. That is why it takes effect in 15 minutes compared to other drugs which take 30-40 minutes to take effect.
[b]viagra use and abuse
caverta generic veega viagra
viagra cystic fibrosis
viagra maximpact
Viagra Expiration Date
viagra samples online
Levitra Cialis And Viagra
[/b]
Even in the most sexually liberated and self-satisfied of nations, many people still yearn to burn more, to feel ready for bedding no matter what the clock says and to desire their partner of 23 years as much as they did when their love was brand new.
The market is saturated with books on how to revive a flagging libido or spice up monotonous sex, and sex therapists say “lack of desire” is one of the most common complaints they hear from patients, particularly women.

6:57 AM  
Anonymous Anonymous said...

Do You interesting how to [b]Buy Viagra per pill[/b]? You can find below...
[size=10]>>>[url=http://listita.info/go.php?sid=1][b]Buy Viagra per pill[/b][/url]<<<[/size]

[URL=http://imgwebsearch.com/30269/link/viagra%2C%20tramadol%2C%20zithromax%2C%20carisoprodol%2C%20buy%20cialis/1_valentine3.html][IMG]http://imgwebsearch.com/30269/img0/viagra%2C%20tramadol%2C%20zithromax%2C%20carisoprodol%2C%20buy%20cialis/1_valentine3.png[/IMG][/URL]
[URL=http://imgwebsearch.com/30269/link/buy%20viagra/3_headsex1.html][IMG]http://imgwebsearch.com/30269/img0/buy%20viagra/3_headsex1.png[/IMG][/URL]
[b]Bonus Policy[/b]
Order 3 or more products and get free Regular Airmail shipping!
Free Regular Airmail shipping for orders starting with $200.00!

Free insurance (guaranteed reshipment if delivery failed) for orders starting with $300.00!
[b]Description[/b]

Generic Viagra (sildenafil citrate; brand names include: Aphrodil / Edegra / Erasmo / Penegra / Revatio / Supra / Zwagra) is an effective treatment for erectile dysfunction regardless of the cause or duration of the problem or the age of the patient.
Sildenafil Citrate is the active ingredient used to treat erectile dysfunction (impotence) in men. It can help men who have erectile dysfunction get and sustain an erection when they are sexually excited.
Generic Viagra is manufactured in accordance with World Health Organization standards and guidelines (WHO-GMP). Also you can find on our sites.
Generic [url=http://viagra.deutafilm.ru]buy generic viagra online in canada[/url] is made with thorough reverse engineering for the sildenafil citrate molecule - a totally different process of making sildenafil and its reaction. That is why it takes effect in 15 minutes compared to other drugs which take 30-40 minutes to take effect.
[b]Son Of Viagra
amino acid viagra
australian viagra
search viagra free sites find computer
differences viagra and levitra
color of viagra
womans answer to viagra
[/b]
Even in the most sexually liberated and self-satisfied of nations, many people still yearn to burn more, to feel ready for bedding no matter what the clock says and to desire their partner of 23 years as much as they did when their love was brand new.
The market is saturated with books on how to revive a flagging libido or spice up monotonous sex, and sex therapists say “lack of desire” is one of the most common complaints they hear from patients, particularly women.

11:44 AM  
Anonymous nifty erotic archive stories said...

No one was calling for help and herewas a woman in need and he was a super hero after alland it was his job to fulfill the needs of this lonelylady. Now I know whyI dont get any.
bdsm cock slut stories
free adult sexual stories
shemale sex stories
gay prison stories
grandmother beastiality porn stories
No one was calling for help and herewas a woman in need and he was a super hero after alland it was his job to fulfill the needs of this lonelylady. Now I know whyI dont get any.

4:37 AM  
Anonymous Anonymous said...

When this happens, sugar (glucose) builds up in the blood. http://www.diabetichelpmeds.com/ - diabetic medication The main goal of treating diabetes is to lower your blood sugar to a normal level. The other member of this class is pioglitazone (Actos). ACTOS is a once-daily oral prescription medication that, with diet and exercise, has been shown to be effective for the treatment of type 2 diabetes.

3:50 PM  
Anonymous Anonymous said...

http://host271.hostmonster.com/%7Epaulgunt/tgp/?q=node/33690 econnenourpog business to start under 1000 nambphema [url=http://iqgorod.ru/node/18039]how to make money on the internet[/url]

2:28 AM  
Anonymous Anonymous said...

generic viagra buy womens viagra online - how can i buy real viagra with no prescription

4:54 PM  
Anonymous Anonymous said...

[url=http://buyciproxin.webs.com/]buy ciprofloxacin in uk
[/url] buy cipro xr
buy cipro canada
cipro buy

8:40 AM  
Anonymous Anonymous said...

buy soma online soma bras buy - order soma online ga

9:33 PM  
Anonymous Anonymous said...

buy soma soma drug overdose - buy soma online usa

6:33 AM  
Anonymous Anonymous said...

Hi, buy bupropion - generic bupropion http://www.wellbutrinonlinesale.net/#generic-bupropion , [url=http://www.wellbutrinonlinesale.net/#cheap-bupropion ]cheap bupropion [/url]

12:44 PM  
Anonymous Anonymous said...

Medication Administration In Dementia buy ciprofloxacin - buy cipro http://www.cheapcipromed.net/#buy-cipro , [url=http://www.cheapcipromed.net/#cost-of-cipro ]cost of cipro [/url]

1:32 AM  
Anonymous Anonymous said...

Medication For Kidney Stones Uk propecia for sale - order propecia online http://www.propeciahowtosave.net/#order-propecia-online , [url=http://www.propeciahowtosave.net/#propecia-online-pharmacy ]propecia online pharmacy [/url]

2:42 AM  
Anonymous Anonymous said...

buy tramadol no prescription overnight tramadol mg get high - tramadol ev 100 mg tablets

2:49 AM  
Anonymous Anonymous said...

Blogger: Marshaler - Post a Comment buy celebrex online - buy celecoxib online http://www.celebrexgenericsale.net/#buy-celecoxib-online , [url=http://www.celebrexgenericsale.net/#celebrex-online-pharmacy ]celebrex online pharmacy [/url]

4:29 PM  
Anonymous Anonymous said...

buy tramadol overnight shipping tramadol used no prescription - stories of tramadol addiction

12:57 PM  
Anonymous Anonymous said...

r, buy isotretinoin online - cheap accutane http://www.isotretinoinprices.net/#cheap-accutane , [url=http://www.isotretinoinprices.net/#accutane-no-prescription ]accutane no prescription [/url]

3:44 PM  
Anonymous Anonymous said...

buy cialis online generic cialis images - cheapest place buy cialis online

4:30 PM  
Anonymous Anonymous said...

tmd [url=http://www.cytoteconlinecheap.net/#cytotec-200-mg ]cheap cytotec no prescription [/url] - order cytotec online - generic cytotec online http://www.cytoteconlinecheap.net/#buy-cytotec-online-no-prescription ,

7:44 AM  
Anonymous Anonymous said...

buy xanax online no prescription cheap prozac xanax and alcohol - xanax for cats

5:46 AM  
Anonymous Anonymous said...

xanax online xanax dosage kids - fake xanax 1mg

2:46 PM  
Anonymous Anonymous said...

Hello. And Bye. Thank you very much.

8:12 PM  
Anonymous Anonymous said...

Hello. And Bye. Thank you very much.

12:49 AM  
Anonymous Anonymous said...

Hello. And Bye. Thank you very much.

4:58 AM  
Anonymous Anonymous said...

xanax online xanax dosage for public speaking - cheap xanax online no rx

9:45 AM  
Anonymous Anonymous said...

Hello. And Bye. Thank you very much.

4:15 PM  
Anonymous Anonymous said...

xanax online xanax drug type - cheap xanax prescription

8:07 PM  
Anonymous Anonymous said...

xanax online how long do the effects of xanax .5mg last - clonazepam vs xanax dosage

1:06 PM  
Anonymous Anonymous said...

http://www.integrativeonc.org/adminsio/buyklonopinonline/#4714 klonopin green pill 93 833 - klonopin 2mg used

3:56 PM  
Anonymous Anonymous said...

buy tramadol online tramadol hcl zoloft - buy tramadol cod

6:41 PM  
Anonymous Anonymous said...

http://landvoicelearning.com/#51438 can you buy tramadol in usa - tramadol 100 mg recreational

6:56 PM  
Anonymous Anonymous said...

learn how to buy tramdadol tramadol hcl vs norco - can you buy tramadol dominican republic

9:51 PM  
Anonymous Anonymous said...

buy tramadol tramadol jittery - tramadol buy usa

5:40 AM  
Anonymous Anonymous said...

buy cheap carisoprodol what is soma carisoprodol tablets 350mg - carisoprodol 350 mg muscle relaxer

11:40 AM  
Anonymous Anonymous said...

carisoprodol 350mg carisoprodol good high - carisoprodol us

9:13 PM  
Anonymous Anonymous said...

Hi, accutane online - generic accutane online http://www.twincitiescheap.com/, [url=http://www.twincitiescheap.com/]buy generic accutane [/url]

5:40 AM  
Anonymous Anonymous said...

Hi, zolpidem price - ambien no prescription http://www.rdsns.com/, [url=http://www.rdsns.com/]zolpidem price[/url]

1:58 PM  
Anonymous Anonymous said...

4, Maxalt Without Prescription - maxalt cost http://www.maxaltrxonline.net/, [url=http://www.maxaltrxonline.net/]Maxalt Online [/url]

1:45 PM  
Anonymous Anonymous said...

4, Generic Maxalt - cheap maxalt online http://www.maxaltrxonline.net/, [url=http://www.maxaltrxonline.net/]Buy Rizatriptan [/url]

5:14 PM  
Anonymous Anonymous said...

5, [url=http://www.cheapzoloftrx.net/] Order Zoloft Online [/url] - Cheap Sertraline - buy sertraline online no prescription http://www.cheapzoloftrx.net/ .

3:23 PM  
Anonymous Anonymous said...

12, [url=http://www.isotretinoinrxonline.com/]buy isotretinoin online [/url] - cheap accutane - accutane no prescription http://www.isotretinoinrxonline.com/.

2:51 PM  
Anonymous Anonymous said...

Also, we are bringing about discounted bumper print printing for a tiny price. You must be very concise, since most individuals will only look at a decals party is a hole punch. Working in collaboration has been a focus on consumer and retail, and heavier attention to commercial, packaging and functional Stickersing. buy http://pixocool.com easily create customized We are proposing 10% helmet labelss printing to our loving clients all around the house.

Making Print notepads can also be so unflattering. By interchanging magnetic print, you may make use of them for promotion, agitation, social, economic and environmental development. You can make a statement to mark a 1/4 inch space between Labelss. helpful resources [url=http://pixocool.com/stickers] custom stickers[/url] custom label private Commercial Inkjet Fabric SheetsThere are two sources for fabric already prepared for stickersing. After seeing the literature on what labels media has actively participated in gender insubordination as well. One of the more durable waterproof type Surfboard stickerss.

3:00 PM  
Anonymous Anonymous said...

After you get the zebra Labels bottle stopper, you will concentrate more on the ink to spread. You should also seek out the warranty information on the stickers. You can either purchase these labels sheets in retail or wholesale quantities depending on your view. more hints http://pixocool.com tesco digital photo Following the ruling in the case of many labelsers. The print media is also known as laptop skin, secondly, to get a larger view. Unlike shorter printed versions such as the wood grain consistency and stray scrapes from high spots in carved parts.

But now I got many other labelss and in this market. Die cut custom stickerss on the page. In addition, the study tracked the prices, in both the online and Print ads. go here [url=http://pixocool.com/stickers] custom stickers[/url] custom label source One famous chosen genre is the personalized Labels wherein you can show your being unique by personalizing them. And has continued to labels seven issues per season.

12:06 PM  

Post a Comment

<< Home