Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Wait for event before continuing

Posted on 2014-10-22
3
Medium Priority
?
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 83

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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 …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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