Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Wait for event before continuing

Posted on 2014-10-22
3
Medium Priority
?
225 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 84

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 35

Accepted Solution

by:
sarabande earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 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