为什么timer1永远不会启动?

时间:2015-08-12 15:23:14

标签: c# .net winforms

Video objects = null;
        private void videosInsertRequest_ResponseReceived(Video obj)
        {
            stringProgressReport[0] = obj.Status.UploadStatus;
            backgroundWorker1.ReportProgress(0, 0);
            timer1.Start();
            objects = obj;
        }

此事件我在上传方法中注册,我将视频文件上传到youtube。 使用断点我看到它在事件中得到的线我也在UploadStatus上看到了字符串" Uploaded"

这是上传方式:

 static Video video = null;

        private void UploadVideo(string FileName, string VideoTitle, string VideoDescription)
        {
            try
            {
                UserCredential credential;
                using (FileStream stream = new FileStream(@"D:\C-Sharp\Youtube-Manager\Youtube-Manager\Youtube-Manager\bin\Debug\client_secrets.json", FileMode.Open, FileAccess.Read))
                {
                    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                        GoogleClientSecrets.Load(stream).Secrets,
                        new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
                        "user",
                        CancellationToken.None,
                        new FileDataStore("YouTube.Auth.Store")).Result;
                }
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
                });
                video = new Video();
                video.Snippet = new VideoSnippet();
                video.Snippet.Title = VideoTitle;
                video.Snippet.Description = VideoDescription;
                video.Snippet.Tags = new string[] { "tag1", "tag2" };
                /*upload.comboBox1.BeginInvoke((Action)(() =>
                {
                    video.Snippet.CategoryId = "Gaming";// (upload.comboBox1.SelectedItem as ComboboxItem).Value.ToString();
                }));*/
                video.Status = new VideoStatus();
                video.Status.PrivacyStatus = "public";
                using (var fileStream = new FileStream(FileName, FileMode.Open))
                {

                    const int KB = 0x400;
                    var minimumChunkSize = 256 * KB;

                    var videosInsertRequest = youtubeService.Videos.Insert(video,
                        "snippet,status", fileStream, "video/*");
                    videosInsertRequest.ProgressChanged +=
                        videosInsertRequest_ProgressChanged;
                    videosInsertRequest.ResponseReceived +=
                        videosInsertRequest_ResponseReceived;
                    // The default chunk size is 10MB, here will use 1MB.
                    videosInsertRequest.ChunkSize = minimumChunkSize * 3;
                    dt = DateTime.Now;
                    videosInsertRequest.Upload();

                    while (true)
                    {
                        string status = video.Status.UploadStatus;
                    }
                }
            }
            catch (Exception errors)
            {
                string errorss = errors.ToString();
            }
        }

现在我正在使用计时器来检查视频文件处理的进度。 但是timer1 tick事件没有到达那里。

我使用了一个断点并且它到了行timer1.Start(); 但我还在timer1 tick事件上添加了一个断点,它永远不会到达那里。

    string fff = "";
    private void timer1_Tick(object sender, EventArgs e)
    { 
        fff = objects.ProcessingDetails.ProcessingStatus;
    }

我试过timer1.Enabled = true;现在timer1.Start();但它没有进入嘀嗒事件。

timer1在我的表单设计器中。

0 个答案:

没有答案