Solved

Wait for event before continuing

Posted on 2014-10-22
3
205 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 78

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 32

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 74

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now