Some events dont work in Winform in C#

I am using YoutubeExtractor's dll.. videoDownloader_ProgressChanged and videoDownloader_DownloadFinished events are working in console application but in winform, it doesnt work.. I dont understand why..

    private void btnStart_Click(object sender, EventArgs e)
    {


         string link = textBox1.Text;
         start(link);

    }

    static void start(string link)
    {
        IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);

        DownloadVideo(videoInfos);
    }

    private static void DownloadVideo(IEnumerable<VideoInfo> videoInfos)
    {
        VideoInfo video = videoInfos
            .First(info => info.VideoFormat == VideoFormat.Standard360);

        var videoDownloader = new VideoDownloader(video, Path.Combine("C:/Downloads", video.Title + video.VideoExtension));
        videoDownloader.DownloadFinished += new EventHandler(videoDownloader_DownloadFinished);

        videoDownloader.ProgressChanged += new EventHandler<ProgressEventArgs>(videoDownloader_ProgressChanged);
        videoDownloader.Execute();
    }

    static void videoDownloader_ProgressChanged(object sender, ProgressEventArgs e)
    {
                   //some code..
    }

    static void videoDownloader_DownloadFinished(object sender, EventArgs e)
    {
        //some code..

    }

my second question is, I want to access a form control in a static videoDownloader_ProgressChanged event. e.ProgressPercentage paramter gives me percent of video downloaded. I want to show it in label. But I cant access label because of static event.. I tried to use delegate but nothing changed..

Answers


Please modify both Start() and DownloadVideo() routines to instance methods. Remove 'static' keyword from them and event handlers as well.


Thread off 'videoDownloader.Execute()' and BeginInvoke() in the changed/finished handlers.

Don't call methods that take forever, (in computer terms), in GUI event handlers. If it takes more than about 50ms, thread it off. Any net thingy, eg. something with 'YouTube' in it, will take longer than that just to establish a connection!


Need Your Help

How to get response from https url using curl and shell script

shell curl

I have written a unix script using curl that returns the response headers of the http url.However i would like to do the same for https and i am unable to do so.I need these to check if the sites a...

How to convert an irregular JSON to dictionary or object?

c# json deserialization

I know hot to Deserialize JSONs like { "key1": "value1", "key2": "value2"}