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

Maintain Checked Radio Group after Post

c# asp.net asp.net-mvc http-post radio-group

How can I maintain not only the questions and answers for a radio group, but the checked radio as well after a post that returns an error?

Visual Studio Command Window - Attach To Remote Process?

visual-studio command-line remote-debugging

I was wondering if it is possible to use the command window commands to attach to a remote process? (It gets very annoying for remote debugging to roll through the dialog steps every time.)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.