Facebook.FacebookMediaStream.Dispose C# (CSharp) Method

Dispose() private method

private Dispose ( ) : void
return void
        public void Dispose()
        {
            var stream = GetValue();
            if (stream != null)
                stream.Dispose();
        }
    }

Usage Example

        private void btnPostVideo_Click(object sender, EventArgs args)
        {
            var ofd = new OpenFileDialog
            {
                Filter = "MP4 Files|*.mp4",
                Title = "Select video to upload"
            };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var fb = new FacebookClient(_accessToken);
            var attachment = new FacebookMediaStream
                                 {
                                     ContentType = "video/mp4",
                                     FileName = Path.GetFileName(ofd.FileName)
                                 }.SetValue(File.OpenRead(ofd.FileName));

            // make sure to add event handler for PostCompleted.
            fb.PostCompleted += (o, e) =>
                                    {
                                        attachment.Dispose();

                                        // incase you support cancellation, make sure to check
                                        // e.Cancelled property first even before checking (e.Error!=null).
                                        if (e.Cancelled)
                                        {
                                            // for this example, we can ignore as we don't allow this
                                            // example to be cancelled.

                                            // you can check e.Error for reasons behind the cancellation.
                                            var cancellationError = e.Error;
                                        }
                                        else if (e.Error != null)
                                        {
                                            // error occurred
                                            this.BeginInvoke(new MethodInvoker(
                                                                 () =>
                                                                 {
                                                                     MessageBox.Show(e.Error.Message);
                                                                 }));
                                        }
                                        else
                                        {
                                            // the request was completed successfully

                                            // make sure to be on the right thread when working with ui.
                                            this.BeginInvoke(new MethodInvoker(
                                                                 () =>
                                                                 {
                                                                     MessageBox.Show("Video uploaded successfully");
                                                                 }));
                                        }
                                    };

            dynamic parameters = new ExpandoObject();
            parameters.message = txtMessage.Text;
            parameters.source = attachment;

            fb.PostAsync("me/videos", parameters);
        }