Solved

Wait for event before continuing

Posted on 2014-10-22
3
212 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 81

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 34

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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