• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
.NET Framework Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
.NET Framework Developer Center > .NET Development Forums > Windows Presentation Foundation (WPF) > System.InvalidOperationException
Ask a questionAsk a question
Search Forums:
  • Search Windows Presentation Foundation (WPF) Forum Search Windows Presentation Foundation (WPF) Forum
  • Search All .NET Development Forums Search All .NET Development Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerSystem.InvalidOperationException

  • Thursday, November 08, 2007 5:34 PMAart-Jan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    I keep getting this error System.InvalidOperationException on the first line of the showInterface function:

    progressbar_canvas.Visibility = Visibility.Collapsed;

     This is my code:


    Code Block

    using System;

    using System.Diagnostics;

    using System.IO;

    using System.Net;

    using System.Windows;

    using System.Windows.Controls;

    using System.Windows.Data;

    using System.Windows.Media;

    using System.Windows.Media.Animation;

    using System.Windows.Navigation;

    using Microsoft.Win32;

     

    namespace DialogTest1

    {

        public partial class Window1

        {

            public Window1()

            {

                this.InitializeComponent();

     

                // Insert code required on object creation below this point.

                newDate.Text = DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss");

            }

     

            private void WindowLauncher(object sender, RoutedEventArgs e)

            {

                OpenFileDialog ofd = new OpenFileDialog();

                //ofd.Multiselect = true;

                ofd.Filter = "Afbeeldingen (*.jpg, *.jpeg)|*.jpg*;*.jpeg|Alle bestanden|*.*";

                if (ofd.ShowDialog() == true)

                {

     

                    string filePath = ofd.FileName;

                    string safeFilePath = ofd.SafeFileName;

                    string filePath2 = filePath.Substring(0, filePath.LastIndexOf("\\"));

                    photoDir.Text = filePath2;

                }

            }

     

            private void showInterface()

            {

                progressbar_canvas.Visibility = Visibility.Collapsed;

                heart_design.Visibility = Visibility.Visible;

            }

     

            private void setPhotoDate(object sender, RoutedEventArgs e)

            {

                progressbar_canvas.Visibility = Visibility.Visible;

                heart_design.Visibility = Visibility.Collapsed;

                Process exiftool = new Process();

                exiftool.StartInfo.FileName = "C:\\exiftool.exe";

                exiftool.StartInfo.Arguments = "-overwrite_original -AllDates=\"" + newDate.Text + "\" \"" + photoDir.Text + "\"";

                exiftool.StartInfo.CreateNoWindow = true;

                exiftool.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                exiftool.EnableRaisingEvents = true;

                exiftool.Exited += new System.EventHandler(this.exiftool_Exited);

                exiftool.Start();

     

     

            }

     

            private void exiftool_Exited(object sender, System.EventArgs e)

            {

                MessageBox.Show("Exited");

                try

                {

                    this.showInterface();

                }

                catch (Exception ex)

                {

                    MessageBox.Show("oException" + ex.Message + "\n helplink:" + ex.HelpLink + "\n" + ex.StackTrace + "\n type:" + ex.GetType().ToString());

                }

     

     

     

            }

     

            private void closeWindow(object sender, RoutedEventArgs e)

            {

                this.Close();

            }

        }

    }




     I'm new to c# and I've Googled this problem, but I can't seem to figure out what's wrong.

    Any help?
     

     

     

     

    • ReplyReply
    • QuoteQuote
     

Answers

  • Thursday, November 08, 2007 5:40 PMDrew MarshModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0
    It would be useful to include the full stacktrace of the exception in the future. My guess however is that

    the event is being fired from a thread other than the UI/Dispatcher thread and therefore you will need to marshal the call back to the Dispatcher thread using this.Dispatcher.Invoke.

     

    You can check this out really quick by calling this.CheckAccess() in the Exited event handler. If it's false then my guess is right, if it's true then we will need the details of the exception to figure out exactly what is wrong.

     

    HTH,
    Drew

    • ReplyReply
    • QuoteQuote
     

All Replies

  • Thursday, November 08, 2007 5:55 PMAart-Jan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    You're were right indeed! Thanks for looking into it.
    It works now. Smile

    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement