Jump to content
  • Advertisement
Sign in to follow this  

Refreshing a WPF Window

This topic is 3696 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have created a C++ program that, given a track, will attempt to find a path using a genetic programming algorithm. I have also created a C# application using WPF which will draw both the track and path. In the C# program, I allow the user to select a track file and then generate paths by clicking two buttons, Track and Path. When Path is clicked, I start my C++ program by creating a Process. My C++ app then spits out the path using the StandardOutput and I read this Asynchronously from my C# app. I am trying to create a situation where the C++ app can send out periodic updates to the C# app and the C# app will then display the current path to the user while the C++ app is running in the background. I am able to receive these path updates just fine but my window does not update with the new information. I suspect that the Process's ASynchronous reads are taking a higher priority than the redraw which is why I can not update.
    // this function is called when the "Path" button is clicked
    private void StartEvolutionStrategies( )
      m_progressBar.IsIndeterminate = true;


      es = new Process(); // create my process
      es.StartInfo.WorkingDirectory = workingDirectory;
      es.StartInfo.FileName = "Evolution Strategies.exe";
      es.StartInfo.CreateNoWindow = true;
      es.EnableRaisingEvents = true;
      es.OutputDataReceived += new DataReceivedEventHandler(DataReceivedEventHandler);
      es.Exited += new EventHandler(ExitEventHandler);

      es.StartInfo.UseShellExecute = false;
      es.StartInfo.RedirectStandardOutput = true;
      es.StartInfo.Arguments = trackFilename + " ExtraArguments true";
      es.BeginOutputReadLine(); // begin reading the output asynchronously

    // function called whenever the Process outputs data
    private void DataReceivedEventHandler(Object sender, DataReceivedEventArgs e)
      string line = e.Data as string;
      if ((line == null) || (line == ""))

      if (line.Contains("New Path"))
        path.ClearSegments(); // clears out the old path
      else if (line.Contains("Redraw"))
        Dispatcher.BeginInvoke(DispatcherPriority.Send, new DrawDelegate(Draw));  // draw updates the Window's Canvas and Children
        path.AddSegment(e.Data);  // adds another part of the path

    private void Draw()

      foreach (Triangle tri in m_triangles) // draw the track

      if (m_triangles.Count != 0 && path != null) // draw the path
        Triangle triangle = m_triangles[0];

        Point pos = new Point();
        pos.X = (triangle.Point1.X + triangle.Point2.X) * .5;
        pos.Y = (triangle.Point1.Y + triangle.Point2.Y) * .5;

        path.Draw(m_canvas, pos);


I haven't done much work with multithreading before so any help would be greatly appreciated. ***EDIT*** Maybe this would be more useful in the .Net forum?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!