Solved

Wait for event before continuing

Posted on 2014-10-22
3
208 Views
Last Modified: 2014-10-26
Hi,

I have a method which raises events when a download is complete. However the events are asyncronous so the program continues even though downloads are still in progress.

How do I wait until the 'Download Complete' event is raised?

static void downloadVideo(string filename)
{
	stdFile_.saver.addStream(filename); //Begin Download
	
	(video as _IStream_Events_Event).stopped += (s) => { 
		Console.WriteLine("Download Complete!"); 		
	};
}

Open in new window


How do I do that?
0
Comment
Question by:mhdi
3 Comments
 
LVL 79

Expert Comment

by:David Johnson, CD, MVP
ID: 40398493
it would have to be an synchronous event to wait or you could wait for a semaphore from the event
http://msdn.microsoft.com/en-us/library/bb202737.aspx
0
 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points
ID: 40398646
normally, download was made in a worker thread and the main thread keeps the user interface responsive while the download is in progress. nevertheless the main thread should not allow to start another download or to quit from program until the download is completed or the thread successfully was terminated. to perform that in a synchronous way you would disable all user actions when the download was started and set up a periodical timer where you check whether the event for download completed has been fired or not. if completed you would enable the user actions again and kill the timer. if the user wants to quit while a download is in progress you would raise an event from main thread that the download should be canceled. the worker thread also checks periodically whether the event was fired and would terminate on cancel. the main thread waits until the thread was terminated and quits after that.

Sara
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40399268
What component are you using that executes the download?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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